我需要使用blob将图像文件上传到服务器,但上传后的文件名总是设置为“blob”,或者在下载时,源代码文件的名称+.jpg。我的代码在 Chrome 上工作,但我需要它在 IE10 上工作,不幸的是我不知道如何。我做的是这样的:function uploadBlob() { var fileName = //insert method to get the original filename of the file uploaded here... var blob = dataURItoBlob(dataURL); //this method gets an image, compresses it and returns it as blob var blob2 = new Blob([blob], { type: "image/jpeg" }); blob2.lastModifiedDate = new Date(); blob2.name = fileName; return blob2;}使用 File Constructor 会容易得多,但 IE 和 Edge 不支持它。该函数需要返回一个文件或一个 blob,并且使用我当前的代码上传到服务器就好了,只是文件名不正确。我怎样才能解决这个问题?
3 回答
![?](http://img1.sycdn.imooc.com/533e4c9c0001975102200220-100-100.jpg)
POPMUISE
TA贡献1765条经验 获得超5个赞
您的文件上传是请求的一部分。您可以将文件名作为同一请求的单独参数传递。如果这不是您的选择,那么您可以在上传 blob 之前创建一个请求,方法是发送文件名并设置一个会话变量,因此当 blob 上传时,该变量将在下一个请求时知道。但是,如果可能,请将文件名参数单独传递给请求,而不仅仅是作为 blob 的名称,因为它似乎是您的情况下的错误。
添加回答
举报
0/150
提交
取消