如何从本机模块中访问 Titanium 保存的文件?在我的代码中,我将使用相机 (Ti.Media) 拍摄的照片保存到文件中。然后,我试图从我的模块中读取相同的文件。我将传递nativePath
给模块的方法。但是,我在我的模块中不断收到文件未找到错误。
在相机成功回调中,我有以下代码:
// earlier in the code
var tiexif = require('com.me.tiexif');
Ti.Media.showCamera({
success: function(event) {
console.log("TIEXIF: showCamera.success()");
anImageView.image = event.media; // works
if (Ti.Filesystem.hasStoragePermissions()) {
console.log("TIEXIF: hasStoragePermissions");
var file = Titanium.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'testphoto.jpg');
console.log("TIEXIF: nativePath: " + file.nativePath);
file.write(event.media);
someUILabel.text = tiexif.getExifOrientation(file.nativePath);
} else ...
}, ...
})
我在日志中看到了这一点:
[INFO] TIEXIF: showCamera.success()
[ERROR] File: fail readDirectory() errno=20
[ERROR] File: fail readDirectory() errno=13
[ERROR] File: fail readDirectory() errno=13
[ERROR] File: fail readDirectory() errno=13
[INFO] TIEXIF: hasStoragePermissions
[INFO] TIEXIF: nativePath: file:///storage/emulated/0/com.me.exiftest/testphoto.jpg
[WARN] ExifInterface: Invalid image.
[WARN] ExifInterface: java.io.FileNotFoundException: file:/storage/emulated/0/com.me.exiftest/testphoto.jpg: open failed: ENOENT (No such file or directory)
我试过用externalStorageDirectory
, applicationDataDirectory
, tempDirectory
, 和applicationCacheDirectory
所有的结果都是一样的。