Javascript从amazon s3桶下载文件?
问题描述:
我正在尝试从Amazon S3上的一个存储桶中下载一个文件。我想知道如果我可以写一个javascript从一个桶中下载这样一个文件。我正在搜索它,但找不到任何可以帮助我的资源。
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.
一些步骤是:验证Amazon S3,然后提供bucket名称,和文件(键),下载或读取文件,以便我可以在文件中显示数据。
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 = new 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
}
}
);