1
發送圖像,我想與http.post發送圖像。我使用該代碼塊,但給我404錯誤。我嘗試了郵差的API,返回成功。如何使用http.post
哪裏是我的錯嗎?
謝謝。
changeprofileimg()
{
this.camera.getPicture({
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: this.camera.DestinationType.DATA_URL,
quality: 100,
encodingType: this.camera.EncodingType.PNG,
targetHeight:500,
targetWidth:500,
correctOrientation:true
}).then(imageData => {
const image = 'data:image/jpeg;base64,'+imageData;
var veri;
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Authorization' , 'Bearer '+this.globalvars.getToken());
headers.append('Content-Type', 'multipart/form-data');
let options = new RequestOptions({ headers: headers });
let postParams = {
file:image
}
this.http.post("http://.../api/profile/image/upload", postParams, options)
.subscribe(data => {
console.log(data['_body']);
veri=data['_body'];
veri = veri.replace(/\\/g, "");
veri = JSON.parse(veri);
console.log(veri);
});
});
}
我加入這個代碼仍然返回「{」代碼「:404,」狀態「:」失敗「‘消息’:‘文件加載錯誤’}」 –
最有可能是在您的API相關的終點一些問題,因爲你'獲取404 http狀態。 – asmmahmud
但這個API上運行郵遞員成功 –