Я новичок в ionic4 / angular4.i мне нужно загрузить фотографию профиля в database.i, я написал код, но я не знаю, является ли он правильным или нет, и когда я загружаю его, я получаю вышеупомянутую ошибку. backend он использует Django, и backend верен, только другие запросы принимают. извините за плохой отступ.
.ts
getPicture() {
const options: CameraOptions = {
quality: 70,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
allowEdit: false,
sourceType: this.camera.PictureSourceType.CAMERA,
correctOrientation: true,
saveToPhotoAlbum: false
};
this.camera.getPicture(options).then(
imageData => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
this.image = this.sanitizer.bypassSecurityTrustUrl(
"data:Image/*;base64" + imageData
);
// this.imageURI = imageData;
this.profileService
.postInfluencerProfile(this.image, null, null)
.subscribe(
response => {
console.log(response);
},
(error: MavinError) => {
if (error instanceof NotFoundError) {
alert("Not found");
} else {
console.log(error);
}
}
);
},
err => {
// Handle error
}
);
}
service.ts
postInfluencerProfile(
profilePic: File,
name: string,
emailId: string
): Observable<any> {
const url = "****************";
const apiKey = "************";
const sessionID = localStorage.getItem("sessionID");
const formdata = new FormData();
formdata.append("file", profilePic);
console.log(formdata);
const loginContext = {
user_agent:
"Dalvik/2.1.0 (Linux; U; Android 6.0.1; Nexus Player Build/MMB29T)"
};
const postData = {
api_key: apiKey,
session_id: sessionID,
profile_picture: profilePic,
display_name: name,
email_id: emailId
};
const httpOptions = {
headers: new HttpHeaders({
"Content-Type": "multipart/form-data;"
})
};
// delete httpOptions.headers['Content-Type'];
console.log(postData);
return this.http.post(url, postData, httpOptions);
}