Javascript来下载从亚马逊S3存储的文件?亚马逊、文件、Javascript

2023-09-11 09:36:44 作者:万物不及蔡徐坤

我试图从Amazon S3的桶下载文件。我在想,如果我可以写一个JavaScript从水桶下载此类文件。我在Google上搜寻,但没有找到任何资源,可以帮助我做到这一点。

I was trying to download a file from a bucket on Amazon S3. I was wondering if I can write a javascript to download such a file from a bucket. I was googling it, but couldn't find any resources that can help me do that.

在心中有些步骤是:验证亚马逊S3,然后通过提供斗名和文件(键),下载或阅读文件,这样我可以能够显示文件中的数据。

Some steps in mind are: authenticate Amazon S3, then by providing bucket name, and file(key), download or read the file so that I can be able to display the data in the file.

谢谢

推荐答案

也许你可以使用 AWS Node.js的API :

var AWS = require('aws-sdk');
AWS.config.update(
  {
    accessKeyId: ".. your key ..",
    secretAccessKey: ".. your secret key ..",
  }
);
var s3 = AWS.S3();
s3.getObject(
  { bucket: "my-bucket", key: "my-picture.jpg" },
  function (error, data) {
    if (error != null) {
      alert("Failed to retrieve an object: " + error);
    } else {
      alert("Loaded " + data.ContentLength + " bytes");
      // do something with data.body
    }
  }
);
 
精彩推荐
图片推荐