标签: cordova-plugin-file

cdvfile不支持的URL错误://

问题:

在我的应用程序中,我想通过cordova wkwebview访问图像.HTML元素如下所示.

<img src="cdvfile://localhost/library-nosync/MyFolder/file.jpg">
Run Code Online (Sandbox Code Playgroud)

在加载时,我收到错误"无法加载资源:不支持的URL".我正在使用iOS 10.2.

经验证/尝试的事情:

如果选中"myFolder"文件夹下"cordova.file.dataDirectory"中的文件列表,我确实会看到"file.jpg".它的原生URL为file:///var/mobile/Containers/Data/Application/app_id/Library/NoCloud/MyFolder/file.jpg.

我在Content-Security-Policy中添加了"img-src'self'cdvfile:".

我在config.xml中添加了以下内容

<access origin="cdvfile://*" /> 
<allow-navigation href="cdvfile://*" /> 
<allow-intent href="cdvfile://*" />
<preference name="iosPersistentFileLocation" value="Compatibility" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
Run Code Online (Sandbox Code Playgroud)

URL中没有特殊(非ASCII)字符,如与此错误相关的线程中所述.还有什么可能是"不支持的URL"的原因?

我访问cdvfile://路径的方式是不正确的?

更新

我遇到了一个链接(忘了捕获),说webview需要相对路径,因此cdvfile://不起作用.我尝试将图像源更改为相对路径,将其更改为"../../../../../../../../..//var/mobile/Containers/数据/应用程序/ app-id/Library/NoCloud/MyFolder/file.jpg"我现在可以看到一个新错误 - "无法加载资源:操作无法完成.操作不允许"

我可以通过"读取"文件的内容并将该base64数据作为图像源传递来使图像工作.但那应该是怎么回事,不是吗?

ios cordova wkwebview cordova-plugin-file

7
推荐指数
2
解决办法
2449
查看次数

为什么我的IOS应用程序拒绝cdvfile://和file:///链接?

我在我的angular/ionic/cordova应用程序中显示下载到cordova.file.dataDirectory的图像时遇到问题.

我正在使用cordova-plugin-file,我可以下载文件,并使用.toInternalURL()和/或.toURL()提取URL.但是,角度列表视图拒绝它们.我正在使用WkWebView for Ios,我的代码在Android上工作正常(使用.toInternalURL()).我已在配置和元内容安全策略中将cdvfile://*和file:///*列入白名单......

我添加了屏幕截图这里是.toInternalURL()生成的链接的控制台屏幕截图

这是.toURL()生成的链接的屏幕截图:

这是我使用的安全策略:

<meta http-equiv="Content-Security-Policy" content="default-src * data: cdvfile://* content://* file:///*; style-src 'self' 'unsafe-inline' *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; media-src *">
Run Code Online (Sandbox Code Playgroud)

filesystems ios angularjs cordova cordova-plugin-file

6
推荐指数
1
解决办法
2507
查看次数

调用window.resolveLocalFileSystemURL时,无法在Chrome中使用cordova-plugin-file:SecurityError

我使用最新的cordova与浏览器平台(我知道这是一些非常实验性的).

我需要在cordova.file.dataDirectory目录中读写.filePluginIsReady事件在Chrome中正确触发,我将读/写操作放在其回调中.

我使用cordova-plugin-file(最新版),与Firefox和Internet Explorer 11配合使用,但是使用谷歌Chrome,调用window.resolveLocalFileSystemURL总是引发这个FileError:

代码:2消息:"确定某些文件在Web应用程序中访问不安全,或者对文件资源进行了太多调用." 名称:"SecurityError"

我仔细阅读了cordova-plugin-file README以及有关浏览器和chrome的问题(授予大配额,初始化文件系统).

向chrome launcher添加--allow-file-access选项无助于访问filesystem:file:/// persistent /.

使用cordova-plugin文件中Chrome的特定代码,我希望它能完美运行.任何线索?

javascript google-chrome cordova cordova-plugin-file

6
推荐指数
0
解决办法
937
查看次数

Cordova android - 如何用生成的替换自定义build.gradle

我有一个cordova项目,我在其中添加了android平台.现在我需要使用build.gradle文件而不是生成的文件.

在plugins.xml中,我有以下代码来做到这一点.

<framework src="src/android/build.gradle" custom="true" type="gradleReference" />
Run Code Online (Sandbox Code Playgroud)

但是在添加插件时,这个build.gradle已经放在包下了.看起来像这样.

// PLUGIN GRADLE EXTENSIONS START
apply from: "com.test.Name/Name-build.gradle"
// PLUGIN GRADLE EXTENSIONS END
Run Code Online (Sandbox Code Playgroud)

而且我在生成的build.gradle中遇到错误.

Error:(89, 0) Cannot convert relative path libs to an absolute file.
Run Code Online (Sandbox Code Playgroud)

我需要我的自定义build.gradle替换自动生成的.请告诉我如何在plugin.xml中指定它我使用的cordova版本是6.1.1

android cordova build.gradle cordova-plugins cordova-plugin-file

5
推荐指数
1
解决办法
1万
查看次数

撤销“存储文件”权限

我的问题与Chrome浏览器有关。我正在使用?ordova和https://github.com/apache/cordova-plugin-file开发应用程序。

该插件要求在最终用户浏览器上使用永久性存储的权限,例如:

在此处输入图片说明

我很久以前单击“允许”,此弹出窗口不再显示。

现在,我想阻止我的用户弹出该窗口,因此,我需要在计算机中撤消该权限才能执行一些测试。

我尝试过各种测试来更改浏览器设置?但我没有成功撤消该许可。我说的不是位置/闪存或其他权限,而是特定的存储权限。

如果有人对如何撤销该线索有任何了解,我将很高兴对其进行测试并提供反馈。

permissions google-chrome file-storage cordova-plugin-file

5
推荐指数
1
解决办法
938
查看次数

Cordova:从 SD 卡读取目录和文件

我正在尝试从 Android 上的外部 SD 卡上的文件夹中读取目录和文件。cordova.file.externalRootDirectory返回的file:///storage/emulated/0/不是 SD 卡的路径。使用cordova.plugins.diagnostic.getExternalSdCardDetails()我获得了 SD 卡的根路径,但如果我尝试读取它,它会返回FileError code: 5.

Cordova 版本:9.0.0 (cordova-lib@9.0.1) Android-API 级别:22

cordova.plugins.diagnostic.getExternalSdCardDetails(function(data) {                 
  window.resolveLocalFileSystemURL(data[0].filePath + "/", 
  $scope.onFSSuccess, $scope.onError);
}, console.log);
Run Code Online (Sandbox Code Playgroud)

$scope.onError 被触发返回错误 5。

this.onError = function(e) {
  console.log(e);
}
Run Code Online (Sandbox Code Playgroud)

创建SD卡文件夹读取器的函数。

this.onFSSuccess = function(fileSystem) {
  fs = fileSystem;
  var directoryReader = fileSystem.createReader();
  directoryReader.localURL = directoryReader.localURL + $scope.dirPath;
  $scope.directoryReaderPath = directoryReader.localURL;
  directoryReader.readEntries($scope.readerSuccess, $scope.onError);
}
Run Code Online (Sandbox Code Playgroud)

注意:我将以下行添加到 config.xml

<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="sdcard,cache" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" …
Run Code Online (Sandbox Code Playgroud)

javascript cordova cordova-plugin-file

5
推荐指数
0
解决办法
672
查看次数

Cordova Android FileReader.readAsDataURL NOT_FOUND_ERR

我在 iOS 和 Android 上使用cordova-plugin-filecordova-plugin-media-capture来捕获视频。此实现在 iOS 上完美运行,但在 Android 上不起作用。我已将问题追溯到FileReader实例无法找到cordova-plugin-media-capture已记录的文件。这是代码块:

if (navigator && navigator.device.capture && window.cordova.file) {
    navigator.device.capture.captureVideo((mediaFiles: MediaFile[]) => {
        if (mediaFiles.length > 0) {
            const mediaFile = mediaFiles[0];
            const type = mediaFile.type;
            window.resolveLocalFileSystemURL((mediaFile as any).localURL, (fileEntry: Entry) => {
                (fileEntry as FileEntry).file((file: File) => {
                    // "file" is a valid file with a local URL (cdvfile://localhost/sdcard/DCIM/....)
                    const fileReader = new FileReader();
                    fileReader.onloadend = (event: ProgressEvent) => {
                        console.log(event);
                        // event.target.error = …
Run Code Online (Sandbox Code Playgroud)

android cordova cordova-plugin-file

4
推荐指数
1
解决办法
1188
查看次数

如何使最终用户可以访问由 Cordova iOS APP 动态生成/保存的文件?

我正在使用cordova-plugin-file将一些数据图像保存到用户的 iOS 手机。

saveBlobAsImageFile(folderpath, filename, blob) {
  const onError = function(msg) {
    // handles error
  }

  window.resolveLocalFileSystemURL(folderpath, function(dir) {
    console.log("Access to the directory granted");
    dir.getFile(filename, { create: true }, function(file) {
      console.log("File created")
      file.createWriter(function(fileWriter) {
        fileWriter.write(blob);
        console.log("Written file")
      }, onError)
    }, onError)
  }, onError)
}
Run Code Online (Sandbox Code Playgroud)

对于folderpath,我尝试了所有这 5 个选项:

let folderpath = cordova.file.syncedDataDirectory;
let folderpath1 = cordova.file.documentsDirectory; 
let folderpath2 = cordova.file.dataDirectory;
let folderpath3 = cordova.file.cacheDirectory;
let folderpath4 = cordova.file.tempDirectory;
Run Code Online (Sandbox Code Playgroud)

运行该函数后saveBlobAsImageFile,日志显示写入成功,但是当我在模拟器/iPhone 中转到文件或库时,我找不到任何已保存的文件。

更新:当我在模拟器中运行时,点击保存后,我发现文件保存在这些文件夹中:

file:///Users/ngoctuan001/Library/Developer/CoreSimulator/Devices/2964FE69-A5FE-4516-B8F1-C45488DBE2B5/data/Containers/Data/Application/1EF9FF0C-903E-481F-87A0-9A1CEDA4DE5D/Library/Cloud/
file:///Users/ngoctuan001/Library/Developer/CoreSimulator/Devices/2964FE69-A5FE-4516-B8F1-C45488DBE2B5/data/Containers/Data/Application/1EF9FF0C-903E-481F-87A0-9A1CEDA4DE5D/Documents/
file:///Users/ngoctuan001/Library/Developer/CoreSimulator/Devices/2964FE69-A5FE-4516-B8F1-C45488DBE2B5/data/Containers/Data/Application/1EF9FF0C-903E-481F-87A0-9A1CEDA4DE5D/Library/NoCloud/ …
Run Code Online (Sandbox Code Playgroud)

ios cordova cordova-ios cordova-plugin-file

3
推荐指数
1
解决办法
475
查看次数

如何使用Cordova在iOS设备上的iCloud中读取文件?

我想阅读存储在iCloud中的PDF文件的内容。

  1. 我使用FilePicker Phonegap iOS插件(https://github.com/jcesarmobile/FilePicker-Phonegap-iOS-Plugin)选择文件。该插件为我提供了文件复制的临时路径。

  2. 我想读一下Cordova文件插件(https://github.com/apache/cordova-plugin-file),但是我做错了什么,日志总是给我一个错误。

这是代码:

$scope.successCallback = function (path) {
    var fileName = path.substr(path.lastIndexOf('/') + 1);
    var fileDir = path.substr(0,path.lastIndexOf('/') + 1)
    console.log("FilePath: " + path);

    $cordovaFile.readAsDataURL(fileDir, fileName)
      .then(function (data) {
          var index = data.indexOf("base64,");
          if(index > 0)
          {
              data = data.substr(index+7);
          }
          console.log("Data OK=" + data);
      }, function (error) {
          console.log("Error reading file: " + JSON.stringify(error));
      });                 
}
window.FilePicker.pickFile($scope.successCallback, $scope.errorCallback);
Run Code Online (Sandbox Code Playgroud)

这就是输出:

$FilePath: /private/var/mobile/Containers/Data/Application/22E33EF4-832B-4911-92A6-312927C42A7C/tmp/DocumentPickerIncoming/file.pdf
$Error reading file: {"code":5,"message":"ENCODING_ERR"}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

filepicker ios angularjs cordova cordova-plugin-file

2
推荐指数
1
解决办法
1534
查看次数

Cordova文件插件 - 将文件保存在设备中

我在Android中保存文件时遇到了很多麻烦.
该项目是使用Ionic与这些插件一起开发的混合应用程序:

com.phonegap.plugins.fileopener 1.0.0 "File Opener"
com.telerik.plugins.nativepagetransitions 0.4.2 "Native Page Transitions"
cordova-plugin-compat 1.0.0 "Compat"
cordova-plugin-crosswalk-webview 2.0.0 "Crosswalk WebView Engine"
cordova-plugin-file 4.2.0 "File"
cordova-plugin-network-information 1.2.2-dev "Network Information"
cordova-plugin-whitelist 1.2.3-dev "Whitelist"
cordova-plugin-wkwebview-engine 1.0.4-dev "Cordova WKWebView Engine"
ionic-plugin-keyboard 2.2.1 "Keyboard"
Run Code Online (Sandbox Code Playgroud)

Android平台版本是5.2.1
我正在使用的设备Samsung A7

这是摘要 AndroidManifest.xml

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)

情况1

如果我尝试使用此片段(实际上正在处理另一个项目)

var storagePath = "/storage/emulated/0";
var fileDir = cordova.file.externalDataDirectory.replace(cordova.file.externalRootDirectory, '');
var fileName = $scope.ngDocument.documentId + ".pdf" …
Run Code Online (Sandbox Code Playgroud)

android cordova cordova-plugins ngcordova cordova-plugin-file

2
推荐指数
1
解决办法
1万
查看次数