let fileReader = new FileReader();
fileReader.readAsDataURL(file);
readAsDataURL方法读取较小的文件(低于5mb)文件并上传也工作fine.But当我上传较大的文件( 24MB)它不读取它们,filereader.result在IE browser.In浏览器中得到null它工作正常。
发布于 2017-03-09 08:30:20
不需要使用FileReader API。直接流式传输file
对象的效率更高。
var config = { headers: { 'Content-Type': undefined } };
$http.post(url, file, config)
.then(function (response) {
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
console.log("Success");
return response;
}).catch(function (errorResponse)
console.log("Error");
throw errorResponse;
});
XHR Send Method知道如何流式传输file
对象,因为它们只是一种特殊类型的Blob。这避免了将所有文件放入内存的开销。
同样重要的是,将内容类型标头设置为undefined
,以便XHR send method可以设置内容类型标头。否则,AngularJS框架将使用内容类型application/json
覆盖。
有关详细信息,请参阅AngularJS $http Service API Reference。
https://stackoverflow.com/questions/42689377
复制相似问题