html文件上传保存-(.html and string translate into .html )
//上传h5编辑器编辑的html内容
uploadHtml(newsId?: any) {
const news = newsId !== undefined ? newsId : 'new';
let uploadFile = this.dataURLtoBlob(`data:text/html;base64,${new Buffer(this.newsInfo.content).toString('base64')}`) ;
let form = new FormData();
form.append(`news_${news}.html`, uploadFile , `news_${news}.html`);
return this.smartrecService.uploadFile(form, 'html');
} //将h5编辑器编辑好的html内容组装成blob对象
dataURLtoBlob(dataurl: string) {
const arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
} //通过contentId获取h5编辑器编辑的html内容,并转化为字符串
getHtml(contentId: any): void {
const url = this.smartrecService.getContentUrlById(contentId);
let xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.responseType = "arraybuffer";
xhr.send();
xhr.onreadystatechange = function() {
if ( xhr.readyState == 4 && xhr.status == 200 ) {
const htmlBuffer = new Buffer(new Uint8Array(xhr.response));
const htmlStr = htmlBuffer.toString();
try {
JSON.parse(htmlStr);
} catch(e) {
this.newsInfo.content = htmlStr;
}
}
}.bind(this);
}
html文件上传保存-(.html and string translate into .html )的更多相关文章
- struts2文件上传(保存为BLOB格式)
html文件:提供上传文件的入口 <input type="file" name="upload"><!-- name很重要,与后面actio ...
- ThinkPHP上传返回 “文件上传保存错误!”
这个问题,最终的由于 Local.class.php中的iconv('utf-8', 'gb2312' ,$filename)的问题 因为我上传的文件名中有 "-" 这个符号. i ...
- extjs采用fileupload进行文件上传后台实现
前台js: form: Ext.define("GS.base.BasicImportForm",{ extend:"Ext.form.Panel", ...
- struts2实现文件上传(多文件上传)及下载
一.要实现文件上传,需在项目中添加两个jar文件 二.上传准备的页面 注:必须植入enctype="multipart/form-data"属性,以及提交方式要设置成post &l ...
- THINKPHP源码学习--------文件上传类
TP图片上传类的理解 在做自己项目上传图片的时候一直都有用到TP的上传图片类,所以要进入源码探索一下. 文件目录:./THinkPHP/Library/Think/Upload.class.php n ...
- Struts2文件上传和文件下载
一.单个文件上传 文件上传需要两个jar包: 首先制作一个简单的页面,用于实现文件上传 <h1>单个文件上传</h1> <s:form action="uplo ...
- Struts2 文件上传和文件下载
一.单个文件上传 文件上传需要两个jar包: 首先制作一个简单的页面,用于实现文件上传 <h1>单个文件上传</h1> <s:form action="uplo ...
- ASP.NET MVC下使用文件上传
这里我通过使用uploadify组件来实现异步无刷新多文件上传功能. 1.首先下载组件包uploadify,我这里使用的版本是3.1 2.下载后解压,将组件包拷贝到MVC项目中 3. 根目录下添加新 ...
- 文件上传&文件下载
一.单个文件上传 文件上传需要两个jar包: 首先制作一个简单的页面,用于实现文件上传 <h1>单个文件上传</h1> <s:form action="uplo ...
随机推荐
- python中的函数和变量
本节内容 函数的定义方法 函数功能 函数的返回值 函数的形参与实参 全局变量与局部变量 递归 函数的作用域 匿名函数lambda 函数式编程 常用内置函数 其他内置函数 函数 函数的定义方法 函数就相 ...
- [邀月博客] SQL Server 2008中SQL增强之二:Top新用途
top数为变量时 declare @intTop intset @intTop=2print @intTop --set rowcount @intTop--select * from [dbo].[ ...
- Java框架spring 学习笔记(八):注入对象类型属性
使用set方法注入对象属性 编写UserDao.java文件 package com.example.spring; public class UserDao { public void print( ...
- 解决Oracle数据库空间不足问题
//查询表空间的大小以及文件路径地址select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space ...
- python字符串之format格式化函数
学习中~ 觉得应该系统地学习一下python,今天学习了字符串,以下是自己的笔记. 首先说一下format函数,用{}和:代替了%,比如: >>>“{} {} {}”.format( ...
- Python的安装图解
安装步骤: 第一步:打开Python官网:http://www.python.org 第二步:点击Download,下载windows版本 第三步:选择要下载的版本第四步:安装到指定的位置第五步:验证 ...
- jQuery.validate.js 自定义错误信息
var validate = $("form").validate({....})validate.showError({"username":"us ...
- python基础 (装饰器,内置函数)
https://docs.python.org/zh-cn/3.7/library/functions.html 1.闭包回顾 在学习装饰器之前,可以先复习一下什么是闭包? 在嵌套函数内部的函数可以使 ...
- Luogu3579 Solar Panels
整除分块枚举... 真的没有想到会这么简单. 要使一个数 \(p\) 满足 条件, 则 存在\(x, y\), \(a<=x \times p<=b\ \&\&\ c< ...
- 对DOM,SAX,JDOM,DOM4J四种方法解析XML文件的分析
1.DOM 与平台无关的官方解析方式 DOM是一次性把xml文件加载到内存中,形成一个节点树 对内存有要求 2.SAX java提供的基于事件驱动的解析方式 每次遇到一个标签,会触发相应的事件方法 3 ...