我正在尝试遵循拍照并获取 FileEntry 对象 https://github.com/apache/cordova-plugin-camera#module_camera.getPictureCordova 相机插件的示例。我正在使用 Cordova Simulate
Visual Studio 2017 通过选择“在浏览器中模拟”来测试示例
拍照有效并且图像显示在模拟器中,使用相同的imageUrl
在此代码片段中传递给 Cordova 文件插件:
function cameraSuccess(imageUri) {
window.resolveLocalFileSystemURL(imageUri, function () {
console.log('success')
}, function (error) {
console.log(error.message);
});
return imageUri;
}
但是,对resolveLocalFileSystemURL 的调用失败并出现以下错误:
提供给 API 的 URI 格式错误,或者生成的数据 URL 已损坏
超出了数据 URL 的 URL 长度限制。
我需要做什么才能使其正常工作?
EDIT我在以下位置找到了这条指令Chrome 怪癖 https://www.npmjs.com/package/cordova-plugin-file#chrome-quirks插件文档的部分
solveLocalFileSystemURL 方法要求入站 url 具有
文件系统前缀。例如,url 参数为
resolveLocalFileSystemURL 应采用以下形式
filesystem:file:///persistent/somefile.txt 而不是形式
Android 中的 file:///persistent/somefile.txt。
所以我将代码更改为:
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);
});
现在错误信息是:
已确定某些文件在 Web 应用程序中访问不安全,或者对文件进行了太多调用
资源。
Chrome 的另一个怪癖是:
Chrome 需要 --allow-file-access-from-files run 参数来支持
通过 file:/// 协议的 API。
目前尚不清楚 Cordova Simulate 是否会以此论点启动 Chrome。这个问题之前已经提出过:
Cordova:使用 VS 2017 中的 --allow-file-access-from-files 启动 chrome https://stackoverflow.com/q/47154220/150342
无法在 Chrome 中使用 cordova-plugin-file :调用 window.resolveLocalFileSystemURL 时出现 SecurityError https://stackoverflow.com/q/34925292/150342
那么也许解决方案是让 Cordova Simulate “允许文件访问文件”?我将如何检验这个假设?
EDIT测试假设的一种方法是从命令行运行模拟器,如下面评论中的建议这个答案 https://stackoverflow.com/a/48854125/150342。您可以通过键入以下命令来运行命令chrome://version/
启动模拟器后在地址栏中。我添加了标志--allow-file-access-from-files
and --unlimited-quota-for-files
,但遇到了相同的安全错误