简体   繁体   中英

How to specify local destination path when using Amazon S3 GetObject -Aws sdk 2.2.6

The following code successfully downloads data from my S3 storage using Aws-sdk 2.2.6.

    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();
      });
    };
  });

How can I modify this code to save the downloaded data to a specific local file path on the front end.

The "fs" is a nodejs related object for interacting with the server file system, but this snippet appears to be front end code.

If you're trying to alter where the file stores for the front end, you can't, that's controlled by the browser. If you're saving a file on the server, you can use the fs object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM