处理文件、图片的上传与下载,再获取到File的文件流传递到后台时是object File格式,后台需要格式为binary格式,此时转换方法如下:
Array.from(e.target.file).map(file => {
if (window.FormData) {
let formData = new FormData();
formData.append('file', file);
formData.append(elseData.key, elseData.value);
http.post(url, formData, {
// headers: {
// 'Content-Type': 'multipart/form-data'
// },
isFIle: true,
onUploadProgress (progressEvent) {
if (progressEvent.lengthComputable) {
getType(callback) === 'function' && callback(progressEvent);
}
}
}).then(data => {
resolve(data);
}, error => {
reject(error);
});
} else {
reject(new Error('您的浏览器不支持此类文件上传,请升级浏览器!'));
}
});