Javascript从amazon s3桶下载文件? [英] Javascript to download a file from amazon s3 bucket?

查看:151
本文介绍了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
    }
  }
);

这篇关于Javascript从amazon s3桶下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆