How to get FileEntry object while using Cordova Simulate

一笑奈何 提交于 2019-12-10 12:39:13

问题


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

来源:https://stackoverflow.com/questions/48100633/how-to-get-fileentry-object-while-using-cordova-simulate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!