【发布时间】:2016-10-14 07:38:46
【问题描述】:
我需要在 Aurelia Js 中上传文件。我不知道如何将文件发送到服务器(命中给定的 API)。我有两个疑问,一个是我的“内容类型”,另一个是,我是否需要将我的图像对象更改为任何其他格式。这是我使用的代码,
scanupload.html:
<input type="file" files.bind="selectedFiles" change.delegate="onSelectFile($event)">
scanupload.js:
onSelectFile($event){ var myurl = 'http://cdn.dmiapp.tk/file?authToken=bLNYMtfbHntfloXBuGlSzPueilaHtZx&type=jpg&name=testfile.jpg&organizationId=1&userId=7&sourceType=USER_UPLOADS';
this.httpValueConverter.call_http(myurl,'POST',{file :this.selectedFiles[0]},'fileupload')
.then(data => {
console.log(data);
if(data.meta && data.meta.statusCode == 200) {
console.log('success');
}
});}
httpservice.js:
call_http(url,method,myPostData,action,params) {
return this.httpClient.fetch(url,
{
method: method,
body : myPostData,
headers : {
'authorization': this.authorization,
'Content-Type':'form-data'
}
})
.then(response => response.json());}
错误: 错误请求和不受支持的媒体文件。 还尝试了内容类型,form-data 和 multipart/form-data
【问题讨论】:
标签: content-type aurelia