Javascript从亚马逊s3存储桶下载文件? [英] Javascript to download a file from amazon s3 bucket?

查看:53
本文介绍了Javascript从亚马逊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 进行身份验证,然后通过提供存储桶名称和文件(密钥),下载或读取文件,以便我能够显示文件中的数据.

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从亚马逊s3存储桶下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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