2

NOTE: I was being stupid, for so many things I tried the picture DOES save into my local storage but I kept on checking my gallery (always thought gallery would scan all the images) but somehow it's not in my gallery so I kept on thinking the image didn't save

I'm using phonegap 2.9.0 and playing with the camera API. The phonegap documentation even provided a full html example which you can just copy and paste the code into the www folder and deploy and camera works perfectly just that it wouldn't save the image taken into the local/sd storage. I'm trying to figure out how and been trying for a while can someone give me a hand?

I did do some research before I post this question. I did find a post:

Save image in local storage phonegap

but I tried the code there and somehow it didn't work for me. I also searched a few sites and posts and lots of them just mentioned adding saveToPhotoAlbum: true which was mentioned in the phonegap documentation and I tried which didn't work at all..

I looked through the phonegap 2.9.0 documentation, and saw permissions so I believe I need to add those codes too so I did...

in config.xml I added

<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />

in AndroidManifest I added

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

and in index.html I just used the full example which phonegap. 2.9.0 provided. I think it's too must to paste it here but I believe this is where I need to add something into the code..

// A button will call this function
//
function capturePhoto() {
  // Take picture using device camera and retrieve image as base64-encoded string
  navigator.camera.getPicture(onPhotoDataSuccess, onFail,{ quality: 50,
    destinationType: destinationType.DATA_URL, saveToPhotoAlbum: true });
}

I thought by adding saveToPhotoAlbum: true would work but doesn't seem like it works though.

Can someone give me a hand? The documentation looks easy but gets frustrated when can't figure out what's wrong (:

Community
  • 1
  • 1
WXR
  • 481
  • 1
  • 7
  • 18

2 Answers2

5

Change this

destinationType: Camera.DestinationType.DATA_URL

to

destinationType: Camera.DestinationType.FILE_URI

It will return you the imageuri,For getting the exact location you can make use of filesystem api in phonegap

window.resolveLocalFileSystemURI(imageURI, resolveOnSuccess, fsFail);
function resolveOnSuccess(entry) {
var fileuri = entry.toURL();
//console.log(fileuri);
}
Divesh Salian
  • 1,457
  • 17
  • 30
  • I only changed `destinationType: Camera.DestinationType.FILE_URI` as you said but still nothing happens though, Did try this from some other posts. Is there anything I'm missing? – WXR Nov 19 '13 at 19:18
  • ok I realized, it DOES save but not in gallery that I have to go into local storage and fetch it, no wonder I have been trying so long and lots posts says changing to FILE_URL would work – WXR Nov 20 '13 at 02:19
  • It didn't worked ???? R u getting ImageURI ? I have same code which is working.... – Divesh Salian Nov 20 '13 at 07:34
  • I then figured why I couldn't find it in gallery...it's weird! the timestamp for the picture is 1969 dec 12 4pm so in the gallery it's like at far far far far far back of the folder as an old image not like how usually it'll be the FIRST when I open up gallery. That's why I never find it in the first place – WXR Nov 22 '13 at 18:56
  • Hi, i know this thread if from a while back, but did you fix the time stamp issue in the end? Because i am facing the same problem, it just set the time as 1970/01/01. – John Jun 28 '15 at 05:52
0

1.destinationType: Camera.DestinationType.DATA_URL

DATA_URL returns base64 string only here image not store in album;

2.destinationType: Camera.DestinationType.FILE_URL

FILE_URL returns image url. here image stored in album.

if u need both i mean base64 string and image stored in album. you need do something

  • get url from camera success then use File API - FileReader (readAsDataURL) concepts in phonegap

    1. FILE_URL better for android DATA_URL crash the app sometimes for out memory error
Kathir
  • 4,359
  • 3
  • 17
  • 29