cordova-plugin-file-transfer icon indicating copy to clipboard operation
cordova-plugin-file-transfer copied to clipboard

NullPointerException When Downloading File

Open Jack-Drake opened this issue 8 months ago • 5 comments

Bug Report

Problem

What is expected to happen?

The file is downloaded and stored onto the device.

What does actually happen?

An error showing that the file name is null and throws null pointer exception

Information

{"code":3,"source":"https:\/\/sample.io\/images\/logo.png","target":"https:\/\/localhost\/__cdvfile_persistent__\/imgcache\/04a568427e026c9d4dc0275d9ba360c7a24326be.png","http_status":200,"exception":"java.lang.NullPointerException"} java.lang.NullPointerException at java.io.FileOutputStream.<init>(FileOutputStream.java:227) at java.io.FileOutputStream.<init>(FileOutputStream.java:186) at org.apache.cordova.filetransfer.FileTransfer$2.run(FileTransfer.java:796) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

Command or Code

`var fileTransfer = new Private.FileTransferWrapper(ImgCache.attributes.filesystem); fileTransfer.download( img_src, filePath, function (entry) { entry.getMetadata(function (metadata) { if (metadata && ('size' in metadata)) { ImgCache.overridables.log('Cached file size: ' + metadata.size, LOG_LEVEL_INFO); Private.setCurrentSize(ImgCache.getCurrentSize() + parseInt(metadata.size, 10)); } else { ImgCache.overridables.log('No metadata size property available', LOG_LEVEL_INFO); } }); ImgCache.overridables.log('Download complete: ' + Helpers.EntryGetPath(entry), LOG_LEVEL_INFO);

    // iOS: the file should not be backed up in iCloud
    // new from cordova 1.8 only
    if (entry.setMetadata) {
      entry.setMetadata(
        function () {
          /* success*/
          ImgCache.overridables.log('com.apple.MobileBackup metadata set', LOG_LEVEL_INFO);
        },
        function () {
          /* failure */
          ImgCache.overridables.log('com.apple.MobileBackup metadata could not be set', LOG_LEVEL_WARNING);
        },
        {
          // 1=NO backup oddly enough..
          'com.apple.MobileBackup': 1
        }
      );
    }

    if (success_callback) {
      success_callback(entry.toURL());
    }
  },
  function (error) {
    if (error.source) { ImgCache.overridables.log('Download error source: ' + error.source, LOG_LEVEL_ERROR); }
    if (error.target) { ImgCache.overridables.log('Download error target: ' + error.target, LOG_LEVEL_ERROR); }
    ImgCache.overridables.log('Download error code: ' + error.code, LOG_LEVEL_ERROR);
    if (error_callback) { error_callback(error); }
  },
  on_progress
);`

Environment, Platform, Device

[email protected] Android Tablet

Version information

Android Studio: Latest version as of this posting Cordova Plugins: cordova-plugin-device 3.0.0 "Device" cordova-plugin-file-transfer 2.0.0 "File Transfer" cordova-plugin-file 8.1.0 "File"

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

Jack-Drake avatar Jun 27 '24 17:06 Jack-Drake