Need help how to work the fileupload using camera i been trying to solve this 2 weeks now with no luck.
Anyone care to help?
private fromGallery(): void {
this.camera.getPicture({
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
// destinationType: this.camera.DestinationType.FILE_URI,
quality: 100,
// allowEdit: true
}).then(imageData => {
// this.user_photo = "data:image/jpeg;base64,"+imageData;
this.uploadPhoto(imageData);
}, error => {
console.log(JSON.stringify(error));
});
}
uploadPhoto(imageData: any)
{
this.showLoading('Please wait...');
const filetransfer : FileTransferObject = this.transfer.create();
let options : FileUploadOptions = {
fileKey : 'fileToUpload',
fileName : 'name.jpg',
// chunkedMode: false,
// mimeType: "multipart/form-data",
headers:{ Connection: "close"},
// httpMethod : 'post',
}
filetransfer.upload(imageData, 'https://192.168.1.11/api/resumes/uploadthumbnailtest', options).then( (data) => {
this.showError("success : " +JSON.stringify(data));
this.loading.dismiss();
},(err) => {
this.showError("err : " +JSON.stringify(err));
this.loading.dismiss();
});
}
PHP
function uploadthumbnailtest() {
$this->autoRender = false;
$fileElementName = 'fileToUpload';
$error = "";
$msg = "";
$filename = $file_name = "";
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
echo json_encode(array("result"=>"success"));
exit;
}
after click upload this was the response : {“bytesSent”:165739, “responseCode”:302, “response”:"",“objectId”:""}
I need to check if the image is successfully upload. In my php i write a simple code just return “success” message in json format but i cant see it in the response. need help please? sorry if my english is bad.
Version
cli packages:
@ionic/cli-plugin-proxy : 1.5.8
@ionic/cli-utils : 1.19.3
ionic (Ionic CLI) : 3.20.1
global packages:
cordova (Cordova CLI) : not installed
local packages:
@ionic/app-scripts : 3.2.1
Cordova Platforms : none
Ionic Framework : ionic-angular 3.9.2
System:
Android SDK Tools : 26.1.1
Node : v8.9.1
npm : 6.4.1
OS : Windows 10