将Blob转换为文件 [英] Convert blob to file
本文介绍了将Blob转换为文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将Blob转换为javascript文件.
I need to convert a blob to file i javascript.
我正在使用File API
Im using File API
var blob = new Blob(byteArrays, { type: contentType });
这是从读取裁剪图像的函数返回的.
This is return from a function reading a cropped images.
旧的上传功能正在使用$ files作为输入.
The old upload function are using $files as input.
我想将该Blob转换为文件,然后设置名称并在该对象中键入.我该怎么做?
I want to convert that blob to file, and then set the name and type in that object. How do I do this??
推荐答案
很简单:
var blob = new Blob(byteArrays, { type: contentType });
var file = new File([blob], filename, {type: contentType, lastModified: Date.now()});
或者只是:
var file = new File([byteArrays], filename, {type: contentType, lastModified: Date.now()});
该代码可在Chrome和Firefox中运行,但不适用于IE.
The code works in Chrome and Firefox, but not IE.
这篇关于将Blob转换为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文