Search code examples
cordovacordova-pluginsngcordova

FileTransfer Permission issue on Android 6 (API 23) with ngCordova


Question/Issue:

I am getting a permission error doing the following:

(Note: I have tried using videoData[0].fullPath and videoData[0].localURL and videoData[0].toURL() like the docs suggested which didn't make sense to me, but all failed to work.)

$cordovaCapture.captureVideo(options).then(function(videoData) {
    // Video Captures works, however when I try to upload I get permission error below.
    $cordovaFileTransfer.upload(baseUrl + '/api/users/upload', videoData[0].fullPath, options, true)
        .then(function(result) {
            // this never triggers
        }, function(err) {
            // here I get permission open failed:EACCES (Permission denied)
            $scope.debug= err;
        });
});

Am I missing a step here? I tested my API and It handles uploads fine when using Postman. I would expect it to prompt me using the new permission model to ask if I want it to allow it to access my storage, however it never accomplishes this.

Any help is appreciated.


Solution

  • I have tried the same and it works fine in android 6.0

    1. Install the latest cordova-plugin-file-transfer (1.5.1 version)

    2. In your code, you are passing same options to capture and also upload. Try to change the options. Refer https://www.npmjs.com/package/cordova-plugin-file-transfer

        fileTransferOptions = {
               'fileKey'   : 'files',
               'fileName'  : FILE_NAME,
              'chunkedMode': false
          }
      
       $cordovaFileTransfer.upload(serverUrl, videoData[0].fullPath, fileTransferOptions)
                  .then(function (data) {
                      console.log('success');
                  }, function (err) {console.log('error', err)});
      
    3. If permission for storage is not prompted, then permission would not have been enabled. (You can add extra java code for allowing storage access always) For now, you can turn on the storage permission from mobile Settings -> Apps -> goto selected app and click on permission, turn on storage access.

    4. Check whether serverUrl to which you are uploading file is correct or not.

    5. Whitelist the server url.

      <acess origin="YOUR_SERVER_URL"/>' /*Network accesss enable*/ <access origin="http://*/*"/>
      <access origin="https://*/*"/>