簡體   English   中英

Phonegap(Cordova)-找不到文件從FileSystem讀取文件時發生異常

[英]Phonegap (Cordova) - File not found Exception in reading file from FileSystem

為了將一個文件從我的android設備的文件系統發送到一台服務器,我正在使用cordova 3.5和以下代碼(因為您可以閱讀此代碼,因此該文件位於我的下載目錄中):

receivedEvent: function(id) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fsSuccess, fail);

}
function fsSuccess(fs){
    fs.root.getDirectory("Download", {create: false, exclusive: false}, doDirectoryListing, FileError);
}

function doDirectoryListing(dirEntry) {     
    var directoryReader = dirEntry.createReader();
    directoryReader.readEntries(gotFiles, FileError);
}

function gotFiles(entries)
{   
    var wsUrl = "http://myServer/";
    var fileToSend =  "file:///storage/sdcard0/Download/"+entries[0].name, "file:///storage/sdcard0/Download/";
    multipart.uploadFiles(success, error,  wsUrl, fileToSend);  
}

我可以讀取/ Download中解析所有條目的所有文件(名稱),但是我不知道如何獲取需要傳遞到uploadFiles函數的特定文件(例如,條目[0])。

問題:我嘗試以不同的方式進行嘗試,例如將其與“ file:/// storage / sdcard0 / Download /”連接,但始終未找到文件異常

我自己找到了解決方案,

主要是刪除file://

可以通過以下方式獲取: fileToSend.replace("file://", ""));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM