Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:参数“的类型错误”;资料来源;FileTransfer.download的:应为字符串,但未定义。_Javascript_Cordova_Amazon S3 - Fatal编程技术网

Javascript 未捕获类型错误:参数“的类型错误”;资料来源;FileTransfer.download的:应为字符串,但未定义。

Javascript 未捕获类型错误:参数“的类型错误”;资料来源;FileTransfer.download的:应为字符串,但未定义。,javascript,cordova,amazon-s3,Javascript,Cordova,Amazon S3,我最近问了一个关于在手机上下载和存储本地文件的问题。前面的问题是我无法访问本地文件系统。问题解决了,但现在我面临一个新的错误。我以前没有见过这个错误,也无法理解它。到目前为止,我掌握的代码是: function storeFile(bucketName, csvfile){ s3Client.getBucketLocation(params = {Bucket: bucketName},function(err,data){ if(err) console.log("Erro

我最近问了一个关于在手机上下载和存储本地文件的问题。前面的问题是我无法访问本地文件系统。问题解决了,但现在我面临一个新的错误。我以前没有见过这个错误,也无法理解它。到目前为止,我掌握的代码是:

 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);
}`
在上面的代码中,我能够提取区域,并能够访问和创建文件夹。问题是下载时,它会给我一个错误:


未捕获类型错误:FileTransfer的参数“source”的类型错误。下载:应为字符串,但未定义。

您的S3调用是异步的。在调用完成之前,不会定义
url
值。将下载代码移动到
.getBucketLocation
回调中

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);
            var region = data.LocationConstraint;
            var 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");
                            var filePath = d.fullPath + csvfile;
                            //alert(filePath);
                            var 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);
        }
    });

}

可能有人没有定义这些值:
region、bucketName、csvfile
所有值都已定义。我能够将这些变量的内容打印到控制台上。我面临着相同的问题/错误消息,但仅限于某些文件。当我尝试从URL下载pdf文件时:一切正常,但当我尝试从Alfresco DMS服务器下载pdf文件时,失败了。但在这两种情况下,响应内容类型都是相同的:“application/pdf”。你找到解决办法了吗?试了你的建议。我收到源和目标错误<代码>下载错误源https://s3-us-west-2.amazonaws.com/bucketname/filename和“下载错误目标/Amazedata/filename”@PallaviPrasad很遗憾,我无法测试您的代码。原始代码的基本问题是异步S3调用;可能还有其他问题。