@premktr wrote:
I am new to ionic4/angular4.i need to upload the profile pic to database.i wrote code but I don’t know whether it is correct or not and when I am uploading it I am getting the above-mentioned error. backend he is using Django and backend is correct only other requests is accepting
.tsgetPicture() { 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); }
Posts: 1
Participants: 1