Javascript来下载从亚马逊S3存储的文件? [英] Javascript to download a file from amazon s3 bucket?
本文介绍了Javascript来下载从亚马逊S3存储的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从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
}
}
);
这篇关于Javascript来下载从亚马逊S3存储的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文