$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - Save base64 string as image using phonegap? - Stack Overflow|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Save base64 string as image using phonegap? - Stack Overflow

matteradmin15PV0评论

I am getting a base64 string from the server for a png file and i would like to save this image on the file system. It looks like phonegap filewriter only supports binary. Does anyone know how i can convert this base64 string to use in phonegap. I was looking at window.atob and window.btoa but couldnt make sense of things.

I am getting a base64 string from the server for a png file and i would like to save this image on the file system. It looks like phonegap filewriter only supports binary. Does anyone know how i can convert this base64 string to use in phonegap. I was looking at window.atob and window.btoa but couldnt make sense of things.

Share Improve this question asked Jan 29, 2014 at 8:34 vijarvijar 7814 gold badges14 silver badges25 bronze badges 3
  • If its a single file then you can store it in local storage – Divesh Salian Commented Jan 29, 2014 at 8:37
  • my requirement i to save it on the file system – vijar Commented Jan 29, 2014 at 8:39
  • You may want to check this post, it saves dataUrl which is base64 to a png image on android file system – Hazem Hagrass Commented Jan 29, 2014 at 10:05
Add a ment  | 

3 Answers 3

Reset to default 2

You can not use the PhoneGap FileWriter to write binary data. You'd need to write a plugin to send your base64 encoded data to the native side, encode it into binary then write it using native code.

Check out the plugins info at: HERE also take a look at the phonegap source code to see how we do the file writer and you can add some code to do the base64 decode before writing.

As far as I know, phonegap don't provide a way to save an image to the filesystem. You need a phonegap plugin to do that.
Canvas2Image nearly do what you want. It take a canvas id, extract a base64 string from the canvas and save it as an image. You can slightly alter the javascript part of the plugins to accept a base64 string instead of a canvas id.

Just found a good plugin to save BASE64 into filesystem.

Phonegap Image Resizer

window.imageResizer.storeImage(
  function(json) { 
    console.log('Saved to ' + json.url) 
  }, function (error) {
    console.log("Error : \r\n" + error);
  }, imageDataInBase64);

More detail see the ment imageresize.js

Post a comment

comment list (0)

  1. No comments so far