Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not uploading on android 30 #322

Open
brunoalex opened this issue Nov 19, 2021 · 1 comment
Open

not uploading on android 30 #322

brunoalex opened this issue Nov 19, 2021 · 1 comment

Comments

@brunoalex
Copy link

brunoalex commented Nov 19, 2021

on android 10.0.0 using cordova-plugin-file-transfer 2.0.0-dev "File Transfer" and cordova-plugin-file 6.0.2 "File"

the upload from camera stoped working ... it worked before now with target 30 using android 10.0.0
i get Upload failed: Code = 1

using this code :


function uploadImage1() {
console.log("click em foto de perfil");
var nomevar1 = localStorage.getItem("reg_id");
 var evento1 = "eventonome";


// Get URI of picture to upload
navigator.camera.getPicture(
  function(uri) {
    try {
      // Pick image from div
      var img = document.getElementById('pimage1');
      img.style.visibility = "visible";
      img.style.display = "block";
      var imageURI = uri;
      if (!imageURI || (img.style.display == "none")) {
         console.log("Tap on picture to select image from gallery.");
        return;
      }
      // Verify server has been entered
      server = 'https://www.estaff.pt/mobile/uploads/mobile_upload.php'
      console.log("Server "+server);
      if (server) {
        // Specify transfer options
        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName="perfil"+nomevar1;
        options.mimeType="image/jpeg";
        options.chunkedMode = false;

       var params = {};
          params.value1 = nomevar1;
          params.value2 = evento1;

          options.params = params;

        // Transfer picture to server
        var ft = new FileTransfer();

   ft.onprogress = function(progressEvent) {
  if (progressEvent.lengthComputable) {
    var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
     $('.loading_pic').show();
   $('#percentagem').html(perc);
    console.log(perc);
   if (perc == "99") {$('.loading_pic').hide();}
    }
  
};

        ft.upload(imageURI, server, function(r) {
    
         console.log( "Upload successful: "+r.bytesSent+" bytes uploaded.");
          img.src = uri;
          img.width = 125;
          img.height = 125;
         

        },
        function(error) {
         console.log("Upload failed: Code = "+error.code);
        }, options);
      }
      else {
        console.log("Server Not Found");
      }
    }
    catch(exce) {
      alert(exce);
    }
  },
  function(e) {
    console.log("Error getting picture: " + e);
    console.log("No Image Found");
  },
  {
    quality: 85,
    allowEdit: false,
correctOrientatin: true,
    destinationType: navigator.camera.DestinationType.FILE_URI, targetWidth: 600,targetHeight: 600,
    sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,correctOrientation: true 

  }
);
}

any clues ?

@ChrisZinnecker
Copy link

ChrisZinnecker commented Dec 13, 2021

Can you check your logs in android studio?
In my logs there appeared an error The source url is not in the allow list ...
Somehow the allow list (previously the whitelist plugin, that is now included in cordova) didn't work for this plugin on my android installation, even when i allowed every url in my config <access origin="*" />.
My workaround for this:
(I used this command to install the plugin: cordova plugin add https://github.com/apache/cordova-plugin-file-transfer)

  1. Open the FileTransfer.java in your android project and plugins folder (platforms/android/app/src/main/java/org/apache/cordova/filetransfer/FileTransfer.java and plugins/cordova-plugin-file-transfer/src/android/FileTransfer.java for angular with cordova)
  2. Find following code snippet (in my project line 696):
if (!Boolean.TRUE.equals(shouldAllowRequest)) {
    LOG.w(LOG_TAG, "The Source URL is not in the Allow List: '" + source + "'");
   JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, null, 401, null);
   callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
    return;
}
  1. Uncomment these lines or write your own allowed source url check

I hope that fixes your problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants