I need to save an image into Drupal, through the drupal service/file. For what i understand i need to decode the file into a base64 and send this as a payload for the service/file. How can i get to encode the in order to do this???? I want to do this in javascript.
Join them; it only takes a minute:
|
I am the author of angular-base64-upload as mentioned by @GrimurD. This directive works perfectly for this scenario. It parses image(or any other file types) into base64-encoding and attach the file info to a model in your scope. Sample usage:
Once you selected a file,
It also has sample code for decoding the base64 file in your server, using PHP or ruby. |
|||||||||||||
|
I would recommend you to use https://github.com/ninjatronic/angular-base64. After following instructions for using this library, you can simply call:
Don't forget to inject in your module:
|
|||||||||||||||||
|
I know it's quite old, but I came here for a solution. In the end I found out that (if you don't want to use external libraries) loading an image in base 64 is as simple as using javascript FileReader.readAsDataURL() Hopefully my final code will help others beginners like me. It features:
It is also on codepen
|
|||||
|
You don't need AngularJs for that. There is a thread here explaining how to do it using Javascript and canvas: How to convert image into base64 string using javascript |
|||||
|
i found some websites,browser like chrome,ie10..may be support this https://developer.mozilla.org/en-US/docs/Web/API/FileReader?redirectlocale=en-US&redirectslug=DOM%2FFileReader |
|||
|
I was having the same problem and ran into this repository on github. Tried it out and it worked perfectly. |
|||
|