如何使用Cordova应用程序将base64图像保存到设备中?

时间:2016-07-11 12:06:54

标签: angularjs cordova ionic-framework phonegap-plugins phonegap-cli

如何使用cordova Application.i将base64图像保存到设备库中。我将获得base64文本作为回复。

1 个答案:

答案 0 :(得分:0)

您可以在此处找到http://ionicframework.com/docs/v2/native/base64-to%20gallery/

http://ourcodeworld.com/articles/read/80/how-to-convert-a-image-from-the-device-to-base64-with-javascript-in-cordova

https://cordovablogsblogs.wordpress.com/2015/05/29/phonegap-plugin-to-convert-base64-string-to-a-png-image-in-android/

Reference code from here

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {

  var fileTransfer = new FileTransfer();
  var uri = encodeURI("http://www.example.com/image");
  var path = fileSystem.root.toURL() + "appName/example.jpg";

  fileTransfer.download(
    uri,
    path,
    function(entry) {
      refreshMedia.refresh(path); // Refresh the image gallery
    },
    function(error) {
      console.log(error.source);
      console.log(error.target);
      console.log(error.code);
    },
    false,
    {
      headers: {
        "Authorization": "dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
      }
    }
  );

});