ionic app에서 express server로 사진을 업로드하려고합니다. 우편함을 사용하여 서버를 테스트 할 때 서버가 잘 작동하지만 이온보기에서는 작동하지 않습니다 (Mac이 없기 때문에 iPhone에서 테스트 할 수 없음).php를 사용하여 ionic에서 express 서버로 이미지를 게시 할 수 없습니다
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");
}
}
}
를 사용할 때 서버 로그에서 사후 요청을 수신하지 않습니다
여기에 코드입니다.