我正在開發基於phonegap的應用程序,它具有文件傳輸功能。我正在使用phonegap相機插件來選擇圖像文件。該代碼適用於'DestinationType.DATA_URL'。但我無法使用'DestinationType.FILE_URI'訪問文件。問題Phonegap相機插件(DestinationType.FILE_URI)
DestinationType.DATA_URL只是給出圖像文件的內容。但我必須獲取圖像文件名稱&文件路徑及其內容。所以我必須在相機選項中使用'DestinationType.FILE_URI'。下面是我的代碼,
function attachFile() {
var pictureSource=navigator.camera.PictureSourceType;
var cameraOptions = { quality: 49 , destinationType:
Camera.DestinationType.FILE_URI, sourceType: pictureSource.PHOTOLIBRARY };
navigator.camera.getPicture(attachSuccess, attachFail, cameraOptions);
}
function attachSuccess(fileuri) {
filePath = JSON.stringify(fileuri);
console.log("FilePath: "+filePath);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function attachFail() {
console.log("attach failed");
}
function gotFS(fileSystem) {
console.log("gotFS:");
var root = "/"+fileSystem.root.name;
console.log("root: "+root);
filePath = filePath .substring(filePath.indexOf(root));
var imageName = filePath.substring(filePath.lastIndexOf('/'));
var type = imageName.substring(filePath.indexOf('.'));
fileSystem.root.getFile(filePath, null, gotFileEntry, fail);
}
function fail() {
console.log("** failed **");
}
function gotFileEntry(fileEntry) {
console.log("got file entry");
fileEntry.file(gotFile, fail);
}
function gotFile(file) {
console.log("got file");
}
當我稱之爲「attachFile」功能,獲取圖片窗口打開&我能夠選擇映像文件。然後,attachSuccess回調函數正在執行。但我無法使用FILE URI訪問文件。文件URI是越來越如下印刷,
內容://媒體/外部/圖像/媒體/ 5490
我不知道如何可以從這個URI獲得「文件名」或「文件對象」。請建議。 (在Android Kitkat & Lollipop中測試的代碼)
「訪問文件」是什麼意思?你想獲得它的數據作爲二進制流或類似的東西? – UnTraDe 2014-12-15 05:05:51