Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Image outputed as a Data URI? #11

Closed
WeaverOfTheWeb opened this issue Jan 22, 2015 · 6 comments
Closed

[Question] Image outputed as a Data URI? #11

WeaverOfTheWeb opened this issue Jan 22, 2015 · 6 comments

Comments

@WeaverOfTheWeb
Copy link

Would you be able to add a Data URI output option? This plugin works perfectly for my project but I'm needing to save the photos as a data uri, could this be a possible feature that can be implemented?

Thanks for this awesome plugin none the less!

@bogomips
Copy link

bogomips commented Feb 3, 2015

I'd like a similar feature because I need to send the base64 through a webservice

@bogomips
Copy link

bogomips commented Feb 4, 2015

I thought it could be a good idea to use cordova-plugin-file plugin to read file and get base64

@mbppower
Copy link
Collaborator

mbppower commented Feb 4, 2015

Yes, you should use the cordova-file in order to read the picture file and them get the base64.
Please, refer to this documentation: http://docs.phonegap.com/en/edge/cordova_file_file.md.html

readAsDataURL: Read file and return data as a base64-encoded data URL.

@mbppower mbppower closed this as completed Feb 4, 2015
@McGern
Copy link

McGern commented Jan 5, 2016

Would you be able to add an example of using the file documentation please? (or point to a more recent version). I am trying to use the described example but can't work out how to load the file path in the filereader

@rphansen91
Copy link

In case anyone is having issues figuring out how to load the image as base64

Place this code inside of the setOnPictureTakenHandler callback and make sure the file plugin is installed https://github.com/apache/cordova-plugin-file

//LOAD THE FILE AS BASE64
var reader = new FileReader();
reader.onloadend = function (evt) {
      console.log(evt.target.result) // THIS IS THE IMAGE AS BASE64
};
reader.onerror = function (evt) {
};

//LOAD THE FILE FROM DISK
window.resolveLocalFileSystemURL(
            result[0], 
            function (fileEntry) {
                fileEntry.file(function (file) {
                    reader.readAsDataURL(file)
                })
            },
            function (err) {
            }
)

@erperejildo
Copy link
Collaborator

erperejildo commented Jun 16, 2016

@rphansen91 Your code didn't work to me, reader.onloadend never trigger.
I tried as well with this and doesn't work either:

readFile(fileEntry) { // picture
    fileEntry.file(function(file) {
      var reader = new FileReader();
      reader.onloadend = function() {
        console.log("Successful file read: " + this.result);
        displayFileData(fileEntry.fullPath + ": " + this.result);
      };
      reader.readAsText(file);
    }, that.onErrorReadFile);
  }

Uncaught TypeError: Object /data/data/com.drodriguez.foodApp/files/camerapreview_16_06_2016_0918_39_original.jpg has no method 'file'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants