如何從本機模塊訪問由Titanium保存的文件?在我的代碼中,我將用相機拍攝的照片(Ti.Media)保存到文件中。然後,我試圖從我的模塊中讀取同一個文件。我將nativePath
傳遞給模塊的方法。但是,我不斷收到我的模塊中找不到文件錯誤。Titanium/Android訪問由本機模塊在Titanium中創建的文件
在相機成功回調,我有這樣的代碼:
// 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
所有相同的結果。
我正在嘗試使用ExifInterface。構造函數接受一個文檔所指的文件名。我假設這意味着文件路徑,但也許它只是一個相對於應用程序數據目錄的名稱。 https://developer.android.com/reference/android/media/ExifInterface.html#ExifInterface(java.lang.String) – skypanther
好的,我添加了一個fh.imagefactory的鏈接,它打開一個文件並訪問它的exif信息(它會刪除文件的一部分)這應該也適用於你 – miga
謝謝,這與freshheads回購的鏈接是偉大的。這比完成應用程序更好,這樣該模塊對於Ti開發人員來說更容易使用。 – skypanther