简体   繁体   中英

How to copy array into file in phonegap?

I have array of images as follows:

var imageArray = new Array(10);

function onCameraPicSuccess (imgData)  {
  imageArray.push("data:image/jpeg;base64," + imgData);
}

I am copying captured images into this array.

Now how to copy this array into file? I am using phonegap. I want to copy into particular folder like myPhotos in my local place. Any help?

Is it possible to do it in javascript? Or should i call JAVA applet from javascript to write into file?

You can use the FileWriter API to write a string version of your data to the disk.

Quick Example

function win(writer) {
    writer.onwrite = function(evt) {
        console.log("write success");
    };
    writer.write(JSON.stringify(imageArray));
};

var fail = function(evt) {
    console.log(error.code);
};

entry.createWriter(win, fail);

For the whole context, see the Full Example under the FileWriter API here .

You can use the FileReader API to read data back. Remember to call JSON.parse to turn it back to a JavaScript object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM