I need to upload files in Aurelia Js. I don't know how to send file to server(hit to given API). I have two doubts, one is in my 'content-type' and another one is, do i need to change my image object to any other format. Here is the code i used,
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());}
Error : bad request and unsupported media file. Also tried content type, form-data and multipart/form-data