Hi!
I'm building an Phonegap application where I'm trying to upload images from either the Camera of the Photo Library. When uploading an image directly from the camery everything work perfectly; the image is uploaded, and it get recognized as an image. When uploading from the Photo Library though, the (a?) file uploaded to the server, but it cannot bli recognized as an image.
What I'm doing on the remote server is checking that either
- the file-extention is .jpg/.jpeg
- the files mime-type is image/jpeg
Neither is true for an image from the library though. The file name appers to be "1" with no extention, and the mime-type is "application/octet-stream".
The code used to retrieve the images is as follows:
//used to capture images from the camera
function captureCamera() {
displayWaitingMessage("Ansluter kamera");
navigator.camera.getPicture(onCameraSuccess, onCameraFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI });
}
function captureGallery() {
displayWaitingMessage("Opening gallery");
navigator.camera.getPicture(onCameraSuccess, onCameraFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY
});
}
function onCameraSuccess(imageURI) {
saveImage(imageURI);
}
function onCameraFail(message) {
alert("Ooops, that's no good!");
hideAllOverlays();
}
function saveImage(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var ft = new FileTransfer();
ft.upload(imageURI, safeDomain+"/common/mobApp/ajax/uploadImage", win, fail, options);
}
function win(r) {
alert("Upload confirmed");
loadUrl("/common/mobApp/viewImage");
}
function fail(error) {
alert("Ooops, we had an error!");
loadUrl("/common/mobApp/viewImage");
}
Any ideas?
Am I forgetting something when picking the image up from the gallery?