[英]object file being sent instead of file information while trying to upload file through http
試圖通過Angular $ http上傳文件。 我正在設置Content-Type並使用FormData對象將其包裝起來,如大多數地方所建議的那樣。 但是,瀏覽器在http請求的請求有效負載中發送[對象數據]。
服務電話:
let fd = new FormData();
fd.append('file', file);
return $q((resolve, reject) => {
$http.post(url, fd, {
headers: {
'Content-Type': undefined,
'X-Token': undefined
}
}).then(
success => resolve(success.data),
error => reject(error)
);
});
關於為什么瀏覽器無法對此文件進行編碼的想法? 請注意,到目前為止,我已嘗試過docx,zip,mp4文件格式。 它們都產生相同的結果。
請求負載:
------WebKitFormBoundaryqfOlKmKqvArA9pz6
Content-Disposition: form-data; name="file"
[object File]
------WebKitFormBoundaryqfOlKmKqvArA9pz6--
標記使用:
<input type="file" id="file-tutorial-{{$index}}-{{language.iso2}}" name="file-tutorial-{{$index}}-{{language.iso2}}"
onchange="angular.element(this).scope().ctrl.addFile(this);">
Ctrl.addFile:
addFile(element) {
service.uploadFile(element.files[0]);
this.$scope.$digest();
}
element.files [0]或文件對象:
{lastModified:1496720186000
lastModifiedDate:Mon Jun 05 2017 23:36:26 GMT-0400 (EDT)
name:"Adil Sulaiman Resume.docx"
size:25456
type:"application/vnd.openxmlformats-
officedocument.wordprocessingml.document"
webkitRelativePath:""}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.