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 ...
随机推荐
- 【转】未能加载文件或程序集“XXX”或它的某一个依赖项。试图加载格式不正确的程序。
“/xxxxx”应用程序中的服务器错误. ------------------------------------------------------------------------------- ...
- []、()、None的区别
def product(*numbers): if numbers == (): raise TypeError for x in numbers: if not isinstance (x, (in ...
- 项目管理利器maven学习笔记(二):
- Centos 7 docker 启动容器 iptables 报 No chain/target/match by that name
我也遇到这个问题,原因时启动docker服务时没有启动iptables服务导致的(有些docker需要再iptables开放有些端口)解决方法1.启动iptables服务 CentOS 7 以下版本 ...
- React中this.props的主要属性
this.props主要包含:history属性.location属性.match属性 ①history属性又包含 ②location属性又包含 ③match属性又包含
- Freemarker 对于数字的循环
Freemarker 对于数字的循环 格式:[#list count.. as i] ${i} [/#list] ******************************************* ...
- HTML5代码段
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Ubuntu16.04 安装python3.7和pip3
到官网下载源码 装个依赖包:apt-get install libffi-dev 三部曲 ./configure make make install 但此时pip3可能不行,加个local,前提是前面 ...
- Sql 根据当前时间,获取星期一具体日期
--根据当前时间,计算每周一日期,周日为每周第一天 declare @getDate datetime --set @getDate='2018-12-30' set @getDate='2019-0 ...
- 如何用命令将本地项目上传到git[z]
1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点 ...