My backend is a simple Laravel api. and my api is working properly when I use PostMan…
----This is my post man Post Request ----
-----This is my ts cord ----
import { Component } from "@angular/core";
import { IonicPage, NavController, NavParams, normalizeURL } from "ionic-angular";
import { Http, Headers } from "@angular/http";
import "rxjs/add/operator/map";
import { NgForm } from "@angular/forms";
import { ToastController } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';
@IonicPage()
@Component({
selector: "page-creat-actor",
templateUrl: "creat-actor.html"
})
export class CreatActorPage {
actorName:string;
actorCountry:string;
actorFirstMovie:string;
actorBestMovie:string;
actorImdbBestMovie:string;
image:any;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public http: Http,
private toastCtrl: ToastController,
private camera: Camera
) {}
presentToast() {
let toast = this.toastCtrl.create({
message: 'Actor was added successfully',
duration: 4000,
position: 'top'
});
toast.present();
}
selectphoto(){
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
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): base64Image = 'data:image/jpeg;base64,' + imageData;
this.image = normalizeURL(imageData);
}, (err) => {
// Handle error
});
}
onSubmit(form:NgForm){
console.log('img' , this.image);
this.actorBestMovie = form.value.actorBestMovie;
this.actorCountry = form.value.actorCountry;
this.actorFirstMovie = form.value.actorFirstMovie;
this.actorImdbBestMovie = form.value.actorImdbBestMovie;
this.actorName = form.value.actorName;
this.actorpost();
form.reset();
}
actorpost() {
// let headers = new Headers();
// headers.append("Accept", "application/json");
// headers.append("Content-Type", "multipart/form-data");
let body = new FormData();
body.append('name',this.actorName);
body.append('country',this.actorCountry );
body.append('first_movie',this.actorFirstMovie);
body.append('best_movie',this.actorBestMovie);
body.append('imdb_best_movie',this.actorImdbBestMovie);
body.append('file',this.image);
this.http.post("http://localhost/slreview-api/public/api/actors",body)
.map(res => res.json())
.subscribe(
data => {
console.log("data => ", data);
},
error => {
console.log('Error => ', error);
},
() => {
console.log('Completed!');
this.presentToast();
}
);
}
}
—This is the error ----
—The error line is image requested line —