Giter Site home page Giter Site logo

Comments (6)

rphansen91 avatar rphansen91 commented on May 12, 2024 1

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) {
            }
)

from cordova-plugin-camera-preview.

bogomips avatar bogomips commented on May 12, 2024

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

from cordova-plugin-camera-preview.

bogomips avatar bogomips commented on May 12, 2024

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

from cordova-plugin-camera-preview.

mbppower avatar mbppower commented on May 12, 2024

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.

from cordova-plugin-camera-preview.

McGern avatar McGern commented on May 12, 2024

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

from cordova-plugin-camera-preview.

erperejildo avatar erperejildo commented on May 12, 2024

@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'

from cordova-plugin-camera-preview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.