【发布时间】:2016-07-05 08:06:26
【问题描述】:
我想阅读存储在 iCloud 中的 PDF 文件的内容。
我使用 FilePicker Phonegap iOS 插件 (https://github.com/jcesarmobile/FilePicker-Phonegap-iOS-Plugin) 选择文件。 该插件为我提供了复制文件的临时路径。
我想通过 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);
这就是输出:
$FilePath: /private/var/mobile/Containers/Data/Application/22E33EF4-832B-4911-92A6-312927C42A7C/tmp/DocumentPickerIncoming/file.pdf
$Error reading file: {"code":5,"message":"ENCODING_ERR"}
我做错了什么?
【问题讨论】:
标签: ios angularjs cordova filepicker cordova-plugin-file