如何在使用Amazon S3时指定本地目标路径GetObject -Aws sdk 2.2.6

时间:2015-10-11 16:39:28

标签: javascript jquery amazon-s3 aws-sdk

以下代码使用Aws-sdk 2.2.6从我的S3存储中成功下载数据。

    return $scope.download = function(fileName, indexf) {
      var bucket, params, test;
      $scope.videoFileDownload[indexf] = true;
      test = 0;
      AWS.config.update({
        accessKeyId: 'mykey',
        secretAccessKey: 'mysecret'
      });
      AWS.config.region = 'us-west-2';
      bucket = new AWS.S3({
        params: {
          Bucket: 'mybucket'
        }
      });
      params = {
        Key: fileName
      };
      return bucket.getObject(params, function(err, data) {
        if (err) {
          setAlert(true, 'alert alert-danger', 'Error!', err);
          return false;
        } else {
          $scope.videoFileDownload[indexf] = false;
          setAlert(true, 'alert alert-success', 'Success!', 'File Downloaded');
          setTimeout((function() {
            $scope.uploadProgress = 0;
            $scope.$digest();
          }), 4000);
        }
      }).on('httpDownloadProgress', function(progress) {
        var progresss3;
        progresss3 = Math.round(progress.loaded / progress.total * 100);
        $(".progress .progress-bar").css("width", progresss3 + "%");
        $(".progress .progress-bar").attr("aria-valuenow", progresss3);
        $scope.$digest();
      });
    };
  });

如何修改此代码以将下载的数据保存到前端的特定本地文件路径中。

1 个答案:

答案 0 :(得分:1)

" fs"是与服务器文件系统交互的nodejs相关对象,但此代码段似乎是前端代码。

如果您尝试更改文件为前端存储的位置,则无法通过浏览器控制该文件。如果要在服务器上保存文件,则可以使用fs对象。