问题描述
我正在尝试使用 File API 从blob对象创建图像文件然后将其添加到要通过XHR发送的表单中.像chrome中的护身符一样工作,但是在Microsoft Edge中使应用程序崩溃.
I'm trying to create an image file from a blob-object using the File API and then add it to a form to be sent via XHR. Works like a charm in chrome, but crashes the app in Microsoft Edge.
let file = new File([blobContent], "image.png");
let form = new FormData();
form.append("file", file);
对于将文件附加到表单的文件API或替代方法,是否有其他选择?如果仅将Blob添加到表单中,则不会将其识别为图像.
Are there any alternatives to the File API or workarounds to attach a file to the form? If I just add the blob to the form it's not recognized as an image.
谢谢!
推荐答案
当前IE11和Edge支持FileAPI,但不支持File构造函数.
Currently IE11, and Edge support the FileAPI but not the File constructor.
在发布到caniuse.com
的链接中,有IE和Edge注释,说明不支持File构造函数.我遇到了同样的问题,我的解决方法是使用Blob
而不是File
,然后设置Blob的类型.
In the link that you posted to caniuse.com
, there are notes for IE and Edge stating that the File constructor is not supported. I encountered the same issue and my work around was to use Blob
instead of File
, and then set the type of the blob.
var blob = new Blob([blobContent], {type : 'image/jpeg'});
这篇关于在Microsoft Edge中实例化File对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!