我最近問了一個關於在手機上本地下載和存儲文件的問題。較早的問題是我無法訪問LocalFileSystem。問題解決了,但現在我面臨着一個新的錯誤。我以前沒有看到過這個錯誤,也無法理解它。我到目前爲止的代碼:未捕獲的類型錯誤:FileTransfer.download的參數「源」的類型錯誤:期望的字符串,但未定義。
function storeFile(bucketName, csvfile){
s3Client.getBucketLocation(params = {Bucket: bucketName},function(err,data){
if(err) console.log("Error :: Cannot retrieve bucket location", err);
else {
//console.log(data);
region = data.LocationConstraint;
url = "https://s3-" + region + ".amazonaws.com/" + bucketName + "/" + csvfile;
//alert(url);
}
});
window.requestFileSystem(LocalFileSystem.PERSISTENT,0,
function(fs){
//alert(fs.root.fullPath);
fs.root.getDirectory("Amazedata", {create: true},
function(d){
//console.log("got dir");
filePath = d.fullPath + csvfile;
//alert(filePath);
fileTransfer = new FileTransfer();
console.log('downloading to: ', filePath);
fileTransfer.download(url, filePath,
function (entry) {
console.log(entry.fullPath); // entry is fileEntry object
},
function (error) {
console.log("Some error", error.code);
});
}, onError);
}, onRequestError);
}`
在上面的代碼,我能提取區域和我能夠訪問和創建文件夾。問題是,下載時,它給我的錯誤:
Uncaught TypeError: Wrong type for parameter "source" of FileTransfer.download: Expected String, but got Undefined.
可能這些值中的某個沒有定義:'region,bucketName,csvfile' –
所有的值都被定義。我能夠將這些變量的內容打印到控制檯上。 –
我面臨同樣的問題/錯誤消息,但僅限於某些文件。當我嘗試從URL下載pdf文件時:http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf一切正常,但是當我嘗試從我的Alfresco下載PDF文件時DMS服務器,它失敗。不過,在這兩種情況下,響應內容類型都是相同的:「application/pdf」。你有沒有解決這個問題呢? –