此論壇之前已詢問過此問題,但無法找到令人滿意的解決方案。因此再次提出問題。 我正試圖從互聯網下載並存儲文件到我的手機上的本地文件系統。我收到以下錯誤:未捕獲的參考錯誤:LocalFileSystem未定義
Uncaught ReferenceError: LocalFileSystem is not defined
我到目前爲止的代碼是:
function storeFile(bucketName, csvfile){
var region;
s3Client.getBucketLocation(params = {Bucket: bucketName},function(err,data){
if(err) console.log("Error :: Cannot retrieve bucket location", err);
else {
console.log(data);
region = data;
}
});
var url = "http://s3-"+region+".amazonaws.com/"+bucketName+"/"+csvfile;
window.requestFileSystem(LocalFileSystem.PERSISTENT,0,
function(fs){
filePath = fs.root.fullPath + "/" + csvfile;
fileTransfer = new FileTransfer();
fileTransfer.download(url, filePath,
function (entry) {
console.log(entry.fullPath); // entry is fileEntry object
},
function (error) {
console.log("Some error");
});
}, function(err){
console.log("Request File System failure");
});
}
我是否需要任何插件添加到我的應用程序?我已經添加了File和FileTransfer插件。順便說一下,這個函數在onDeviceReady被觸發後被調用。
編輯: 我沒有與AngularJs合作。我的代碼在NodeJs上。其次,我沒有像離子框架等依賴性,這可能會帶來問題。此相同的代碼已經在其他已成功下載和存儲的數據上進行了測試。我在將代碼更改爲從亞馬遜服務器上的特定位置下載後出現問題。如果有人能爲我解決這個問題,那就太好了。我可以通過代碼訪問存儲區和區域。唯一的問題是LocalFileSystem。
[Cordova:LocalFileSystem is not defined]的可能重複(http://stackoverflow.com/questions/27985512/cordova-localfilesystem-is-not-defined) –