How to get FileEntry object while using Cordova Simulate

928 views Asked by At

I'm trying to follow the Take a picture and get a FileEntry Object example for the Cordova Camera Plugin. I'm using Cordova Simulate in Visual Studio 2017 to test the example by selecting "Simulate In Browser"

Taking a picture works and the image is shown in the simulator, using the same imageUrl that is passed to the Cordova Files Plugin in this code snippet:

function cameraSuccess(imageUri) {
  window.resolveLocalFileSystemURL(imageUri, function () {
    console.log('success')
  }, function (error) {
    console.log(error.message);
  });

  return imageUri;
}

However, the call to resolveLocalFileSystemURL fails with the following error:

A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs.

What do I need to do to get this working?

EDIT I found this instruction in the Chrome Quirks section of the plugin documentation

resolveLocalFileSystemURL method requires the inbound url to have filesystem prefix. For example, url parameter for resolveLocalFileSystemURL should be in the form filesystem:file:///persistent/somefile.txt as opposed to the form file:///persistent/somefile.txt in Android.

So I changed the code to:

  if (device.isVirtual) {
    if (!window.isFilePluginReadyRaised) {
      //added to check another potential Chrome quirk
      //the alert wasn't never shown so I don't think it's an issue
      alert('!window.isFilePluginReadyRaised');
    }

    imageUri= 'filesystem:' + imageUri;
  }

window.resolveLocalFileSystemURL(imageUri, function () {
  console.log('success');
}, function (error) {
  console.log(error.message);
});

Now the error message is:

It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.

Another Chrome quirk is:

Chrome requires --allow-file-access-from-files run argument to support API via file:/// protocol.

It is not clear whether Cordova Simulate launches Chrome with this argument. This problem has been raised before:

Cordova: Launching chrome with --allow-file-access-from-files from VS 2017

Can't use cordova-plugin-file in Chrome : SecurityError when calling window.resolveLocalFileSystemURL

So perhaps the solution is to get Cordova Simulate to "allow-file-access-from-files" ? How would I test that hypothesis?

EDIT One way to test the hypothesis is to run the simulator from a command line as suggested in a comment under this answer. You can get the command to run by typing chrome://version/ in the address bar after launching the simulator. I added the flags --allow-file-access-from-files and --unlimited-quota-for-files, but got the same security error

0

There are 0 answers