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上运行邮递员成功 –