我最近问了一个关于在手机上本地下载和存储文件的问题。较早的问题是我无法访问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”。你有没有解决这个问题呢? –