Android, Camera.PictureSourceType.PHOTOLIBRARY, FileTransfer, why application/octet-stream?

564 views
Skip to first unread message

Tor Claesson

unread,
Nov 7, 2012, 10:44:14 AM11/7/12
to phon...@googlegroups.com
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?

Tor Claesson

unread,
Nov 7, 2012, 10:45:24 AM11/7/12
to phon...@googlegroups.com
Oh, I forgot:
- The device I'm testing on is using Android 2.3.3
- I'm using Cordova 2.1.0

Brian Ritter

unread,
Jul 22, 2013, 5:29:31 PM7/22/13
to phon...@googlegroups.com
Did you ever get this resolved?  What was your final solution?

I have the same issue using phonegap 2.9.0

-Brian

Brian Ritter

unread,
Jul 22, 2013, 5:30:45 PM7/22/13
to phon...@googlegroups.com
Did you ever find a solution for this? what was your solution?

I have the same issue phonegap 2.9.0


On Wednesday, November 7, 2012 10:44:14 AM UTC-5, Tor Claesson wrote:

包四維

unread,
Jul 31, 2013, 11:00:39 AM7/31/13
to phon...@googlegroups.com
The code can completly help you

although it is capture function,but the file upload function is the same

Tor Claesson於 2012年11月7日星期三UTC+8下午11時44分14秒寫道:

Brian Ritter

unread,
Jul 31, 2013, 12:46:43 PM7/31/13
to phon...@googlegroups.com
Here's actually what I used.  This allows you to get the full url.




--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
---
You received this message because you are subscribed to a topic in the Google Groups "phonegap" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phonegap/deQELAf7Gow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages