1

I am developing a phonegap application, in this i'm getting a base64 string from server using ajax.

I want to save this as image into a folder in the device.

I didn't find anything in javascript and jqyery that convert an base64 string to image.

We can display base64 string in image using javascript, but i want to store this image in to a folder so please can you help me to out this problem.

Anto king
  • 1,222
  • 1
  • 13
  • 26
user2075328
  • 423
  • 2
  • 7
  • 16

4 Answers4

0

Since PhoneGap version 2.9 it is possible to store base64 to a folder with the given FileWriter, but only for Android and iOS.

Mainz007
  • 533
  • 5
  • 16
  • hey mate can you explane how to convert base64 string to image because i didn't find any option there i am also using file writer in my project but only for text file not for image – user2075328 Jul 18 '14 at 07:52
  • Well you have a little step in between by converting base64 to binary(utf8). Therefore you can use [window.atob()](https://developer.mozilla.org/en-US/docs/Web/API/Window.atob) and then write the binary to the filesystem with the FileWriter (example is on their website). [1]:https://developer.mozilla.org/en-US/docs/Web/API/Window.atob – Mainz007 Jul 18 '14 at 08:38
0

Another approach

  1. You can directly assign base64 string as src attribute to an image tag.
  2. Use canvas and write image into it.
  3. download canvas as image.

See below links for your help:- Image src: base64 http://code-tricks.com/convert-the-image-to-base64-data-stream/

RAKESH HOLKAR
  • 2,127
  • 5
  • 24
  • 42
0

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.

Sunil Dodiya
  • 2,605
  • 2
  • 18
  • 21
-1

In JavaScript you cannot have the direct access to the filesystem. Refer this link. However if you can use the node.js you can able to save the file, Refer this link. PhoneGap command-line interface and node.js library.

Community
  • 1
  • 1
msnfreaky
  • 1,013
  • 10
  • 14