Apache Cordova `resolveLocalFileSystemURL` function always return error 5 (ENCODING_ERR)

2.1k Views Asked by At

I'm around this issue for some days and no results. I want to have a function that returns the size of a file, but resolveLocalFileSystemURL returns error 5 (ENCODING_ERR)

function getFileSize (fileUri, callback) {
  var fileSize = null
  window.resolveLocalFileSystemURL(fileUri, function (fileEntry) {
    fileEntry.file(function (fileObj) {
      fileSize = fileObj.size
      callback(fileSize)
    },
    function (err) {
      console.error('fileEntry error:\n', JSON.stringify(err))
      callback(fileSize, Error(err))
    })
  },
  function (err) {
    console.error('resolveLocalFileSystemURL error:\n', JSON.stringify(err))
    callback(fileSize, Error(err))
  })
}

I'm using as input something like fileUri = 'file:///storage/9C33-6BBD/DCIM/Camera/20190616_183142.jpg'

Any idea what the problem might be? Any nice simple plugin to get the file size?

specs

I'm using Cordova v 9.0.0 ([email protected]). My plugins are these:

<plugin name="cordova-plugin-statusbar" spec="~2.2.3" />
<plugin name="cordova-plugin-camera-with-exif" spec="~1.2.2" />
<plugin name="cordova-plugin-file" spec="~4.3.3" />
<plugin name="cordova-plugin-network-information" spec="~2.0.1" />
<plugin name="cordova-plugin-geolocation" spec="~2.4.3" />
<plugin name="cordova-plugin-email-composer" spec="~0.8.15" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
<plugin name="cordova-plugin-device" spec="^2.0.2" />
<plugin name="cordova-plugin-inappbrowser" spec="^3.0.0" />
<plugin name="cordova-pdf-generator" spec="^2.0.3" />
<plugin name="info.protonet.imageresizer" spec="https://github.com/protonet/cordova-plugin-image-resizer.git" />
<engine name="android" spec="^6.2.0" />
0

There are 0 best solutions below