イオンサーバーからエクスプレスサーバーに画像をアップロードしようとしています。 Postmanを使ってテストするとサーバーがうまく動作しますが、イオンビューからは動作しません(Macを持っていないためiPhoneでテストできません)。ここphpを使用してイオンサーバーからエクスプレスサーバーに画像を投稿できません
はコードです:
import { ActionSheetController, ToastController, Platform, LoadingController, Loading } from 'ionic-angular';
import { Injectable } from '@angular/core';
import { ApiService } from '../services/api.service';
import { File } from '@ionic-native/file';
import { Transfer, TransferObject } from '@ionic-native/transfer';
import { FilePath } from '@ionic-native/file-path';
import { Camera } from '@ionic-native/camera';
import { Http, Headers } from '@angular/http';
declare var cordova: any;
@Injectable()
export class imageService {
loading: Loading;
image: string = null;
imageSelected: Boolean = false;
constructor(private http: Http, private camera: Camera, private transfer: Transfer, private file: File, private filePath: FilePath, public actionSheetCtrl: ActionSheetController, public toastCtrl: ToastController, public platform: Platform, public loadingCtrl: LoadingController) { }
takePicture(sourceType) {
// Create options for the Camera Dialog
var options = {
destinationType: this.camera.DestinationType.DATA_URL,
quality: 50,
sourceType: sourceType,
saveToPhotoAlbum: false,
correctOrientation: true
};
// Get the data of an image
this.camera.getPicture(options).then((imageData) => {
this.image = "data:image/jpeg;base64," + imageData;
this.presentToast('Selected Image');
alert("selected image");
this.imageSelected = true;
this.uploadImage();
}, (err) => {
this.presentToast('Error while selecting image.');
alert("error selecting");
});
}
private presentToast(text) {
let toast = this.toastCtrl.create({
message: text,
duration: 3000,
position: 'top'
});
toast.present();
}
uploadImage() {
if (this.imageSelected) {
this.presentToast("image is selected");
alert("image is selected");
this.http.post("http://appserver.com:8080/sql_api/profilePic", { image: this.image }, function(err, res){
if(err){
console.log("ERROR", err);
alert("Error with request");
}else{
console.log(res);
alert("success in callback");
this.presentToast('image posted successfully');
}
});
}
else {
this.presentToast('image not selected');
alert("image not selected");
}
}
}
それを使用しているとき、私は、サーバーログから任意のPOSTリクエストを受信しません。