How to move captured image taken by Android phone to another folder using Phonegap?

1,829 views
Skip to first unread message

Kasturi Unde

unread,
Mar 29, 2012, 8:42:52 AM3/29/12
to phonegap
I am working on Phonegap 1.5.0, Our project needs to copy picture
taken from camera using Android device and move it to another folder.
All the images are stored in DCIM/100media/camera. How to move those
images to another folder? I am using HTC Wildfire S..

I have tried the examples of Phonegap Developer Guide..

Thanks in advance..

Captain Obvious

unread,
Mar 29, 2012, 2:04:21 PM3/29/12
to phon...@googlegroups.com
See the docs for copyTo(). This has been working ok for me:

myFileSystem = ...;
myDirectoryEntry = ...;
srcFilePath = ...;
srcFileName = ...;
newFileName = ...;

myFileSystem.root.getFile(
    srcFilePath,
    {create: false},
    function(fileEntry) {
        fileEntry.copyTo(
            myDirectoryEntry,
            newFileName,
            function(){
                log('copied photo to: ' + newFileName);
                /*
                fileEntry.remove(
                    function() { log('removed photo: ' + srcFileName + ' (' + newFileName + ')'); },
                    function(error) { log('error removing photo: ' + error.code); }
                )
                */
            },
            function(error) { log('error copying photo: ' + error.code); }
        )
    },
    function(error) { log('error getting photo entry: ' + error.code); }
)

nbk

unread,
May 30, 2012, 7:56:43 AM5/30/12
to phon...@googlegroups.com
function capture() {

   
// Retrieve image file location from specified source
    navigator
.camera.getPicture(getImageURI, function(message) {
        alert
('Image Capture Failed');
   
}, {
        quality
: 40,
        destinationType
: Camera.DestinationType.FILE_URI
   
});

}

function getImageURI(imageURI) {

   
var gotFileEntry = function(fileEntry) {
        alert
("got image file entry: " + fileEntry.fullPath);
       
var gotFileSystem = function(fileSystem){
           
// copy the file
            fileEntry
.moveTo(fileSystem.root, "1.jpg", null, null);
            alert
(fileSystem.root);
       
};
       
// get file system to copy or move image file to
        window
.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fsFail);
   
};
   
//resolve file system for image  
    window
.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail);
}

//file system fail
function fsFail(error) {
    alert
("failed with error code: " + error.code);

}

Simon MacDonald

unread,
Nov 1, 2012, 2:43:13 PM11/1/12
to phon...@googlegroups.com
When the move fails does your error method get called? What do you see
in "adb logcat"?

Simon Mac Donald
http://hi.im/simonmacdonald


On Thu, Nov 1, 2012 at 1:45 PM, Tanin Srivaraphong <tani...@gmail.com> wrote:
> I try this but it doesn't work for me. The copyTo() work but not for
> moveTo(). I want to move my camera data from
> "/mnt/sdcard/Android/data/xxx.xxx.xxx/cache" to
> "/data/data/xxx.xxx.xxx/picture".
>
> Here is my snippet of code
>
> targetImg.moveTo( destinationFile, filename, moveSuccess, moveFail ); // <--
> NOT WORK. File doesn't move to destination file.
>
> targetImg.copyTo( destinationFile, filename, moveSuccess, moveFail ); // <--
> WORK. But not what I want.
>
> ----------
>
> <uses-permission android:name="android.permission.VIBRATE" />
> <uses-permission
> android:name="android.permission.ACCESS_COARSE_LOCATION" />
> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
> />
> <uses-permission
> android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
> <uses-permission android:name="android.permission.INTERNET" />
> <uses-permission android:name="android.permission.RECEIVE_SMS" />
> <uses-permission android:name="android.permission.RECORD_AUDIO" />
> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"
> />
> <uses-permission android:name="android.permission.READ_CONTACTS" />
> <uses-permission android:name="android.permission.WRITE_CONTACTS" />
> <uses-permission
> android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
> />
> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
> <uses-permission android:name="android.permission.BROADCAST_STICKY" />
> <uses-permission android:name="android.permission.DELETE_CACHE_FILES" />
>
> --
> -- 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
>
>

Tanin Srivaraphong

unread,
Nov 1, 2012, 10:59:10 PM11/1/12
to phon...@googlegroups.com
Hi, Simon

Program tell me file move successful but it not correct. File does not move to my target folder. Please see my Logcat below

root@android:/data/data/xxx.xxx.xxx/photo/1 # ls -al
<empty result>

Again. File will appear here if I use copyTo().

Thanks,
Tanin

11-02 09:52:35.416: I/Web Console(905): Capture photo at null:54
11-02 09:52:35.566: D/DroidGap(905): Paused the application!
11-02 09:52:35.566: D/CordovaWebView(905): Handle the pause
11-02 09:52:35.575: D/CordovaWebView(905): >>> loadUrlNow()
11-02 09:52:38.605: W/IInputConnectionWrapper(905): showStatusIcon on inactive InputConnection
11-02 09:52:42.376: D/dalvikvm(905): GC_FOR_ALLOC freed 3026K, 32% free 6835K/9927K, paused 64ms, total 88ms
11-02 09:52:42.376: I/dalvikvm-heap(905): Grow heap (frag case) to 7.893MB for 1228816-byte allocation
11-02 09:52:42.466: D/dalvikvm(905): GC_FOR_ALLOC freed 625K, 26% free 7410K/9927K, paused 84ms, total 84ms
11-02 09:52:42.486: W/CursorWrapperInner(905): Cursor finalized without prior close()
11-02 09:52:42.586: D/dalvikvm(905): GC_CONCURRENT freed 0K, 26% free 7410K/9927K, paused 23ms+19ms, total 125ms
11-02 09:52:42.835: D/dalvikvm(905): WAIT_FOR_CONCURRENT_GC blocked 0ms
11-02 09:52:42.926: W/CursorWrapperInner(905): Cursor finalized without prior close()
11-02 09:52:42.936: D/dalvikvm(905): GC_EXPLICIT freed 1251K, 38% free 6172K/9927K, paused 10ms+12ms, total 101ms
11-02 09:52:42.936: D/DroidGap(905): Resuming the App
11-02 09:52:42.936: D/CordovaWebView(905): >>> loadUrlNow()
11-02 09:52:43.096: W/EGL_emulation(905): eglSurfaceAttrib not implemented
11-02 09:52:43.486: D/CordovaLog(905): file:///mnt/sdcard/Android/data/xxx.xxx.xxx/cache/1351824762265.jpg
11-02 09:52:43.486: D/CordovaLog(905): null: Line 90 : file:///mnt/sdcard/Android/data/xxx.xxx.xxx/cache/1351824762265.jpg
11-02 09:52:43.486: I/Web Console(905): file:///mnt/sdcard/Android/data/xxx.xxx.xxx/cache/1351824762265.jpg at null:90
11-02 09:52:44.126: D/CordovaLog(905): [object Object]
11-02 09:52:44.126: D/CordovaLog(905): null: Line 108 : [object Object]
11-02 09:52:44.126: I/Web Console(905): [object Object] at null:108
11-02 09:52:44.546: D/CordovaLog(905): File move successful
11-02 09:52:44.546: D/CordovaLog(905): null: Line 126 : File move successful
11-02 09:52:44.546: I/Web Console(905): File move successful at null:126
11-02 09:52:44.775: W/EGL_emulation(905): eglSurfaceAttrib not implemented

Simon MacDonald

unread,
Nov 2, 2012, 2:11:23 PM11/2/12
to phon...@googlegroups.com
Arg, sorry I should have caught on before. The root cause of the issue is we are trying to do a move file between two different file systems. The /sdcard is one mount point and /data/data is another. UNIX will not allow you to move files between the two different file systems.

I've created a bug for this:


Which I will fix by detecting the problem and calling the error callback instead of the success callback.

In order for you to do what you want you'll need to do a copyTo and then a remove.

Simon MacDonald

unread,
Nov 2, 2012, 2:54:51 PM11/2/12
to phon...@googlegroups.com
Okay, the bug is fixed for 2.3.0 which won't be out for a month. In the meantime do a copy/delete to work around your issue.

Tanin Srivaraphong

unread,
Nov 3, 2012, 1:02:25 AM11/3/12
to phon...@googlegroups.com
Thanks Simon :)

nandini g

unread,
Dec 19, 2017, 11:27:08 AM12/19/17
to phonegap
Hi All,,

I am not able to copy images from one folder to another.Could you please help me here.Please find the code below.

By default ,the images are getting stored in the below path after image capture but I want to move this to configured folder.

/storage/emulated/0/Andriod/data/com.opentext.mobile.android/cache/1513428858022.jpg'




self.copyImage=function () {
var awMobFileSys = new Appworks.AWMobileFileSystem();


var source='/storage/emulated/0/Andriod/data/com.opentext.mobile.android/cache/1513428858022.jpg';
var dest='/storage/emulated/0/Andriod/data/com.opentext.mobile.android/files/1513428858022.jpg';
awMobFileSys.copy(source,true,dest,true,true,false);
alert("source"+source);
alert("dest"+dest);
var source1='file:///storage/emulated/0/Andriod/data/com.opentext.mobile.android/cache/1513428858022.jpg';
var dest1='file:///storage/emulated/0/Pictures/1513428858022.jpg';
awMobFileSys.copy(source1,true,dest1,true,true,false);
alert("called second copy function");

/*awMobFileSys.copy('//storage//emulated//0//Andriod//data//com.opentext.mobile.android//cache//1513428858022.jpg',true,'//storage//emulated//0//Andriod//data//com.opentext.mobile.android//files//1513428858022.jpg',true,true,false);*/
/*awMobFileSys.copy('file:///storage/emulated/0/Andriod/data/com.opentext.mobile.android/cache/1513428858022.jpg',true,'file:///storage/emulated/0/Andriod/data/com.opentext.mobile.android/files/1513428858022.jpg',true,true,false);*/

/* awMobFileSys.download('file:///storage/emulated/0/Andriod/data/com.opentext.mobile.android/files', '1513428858022.jpg');*/
awMobFileSys.download('file:///storage/emulated/0/Andriod/data/com.opentext.mobile.android/cache/1513428858022.jpg','file:///storage/emulated/0/Andriod/data/com.opentext.mobile.android/cache/1513428858022.jpg',null,false,true,false);

};
Reply all
Reply to author
Forward
0 new messages