Phonegap: save base64 image to gallery

后端 未结 3 1074
甜味超标
甜味超标 2021-01-07 13:04

I just wanna save an image base64 and open it on gallery. I don\'t want to get pictures from gallery or take pictures.




        
3条回答
  •  情歌与酒
    2021-01-07 13:57

    Solution:

    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=="
          }
        }
      );
    
    });
    

    I needed to create a plugin to refresh the image gallery, because when you save an image on android device, this image does not appears on gallery. This plugin updates the image gallery.

    refreshMedia.refresh(path); // Refresh the image gallery
    

    Plugin: https://github.com/guinatal/refreshgallery

提交回复
热议问题