如何使用Node.js在AWS中创建新的S3存储桶?

时间:2018-11-12 07:22:12

标签: node.js amazon-s3

如何使用nodejs在AWS中创建新的S3存储桶?

我需要在s3存储桶上上传大量图像文件,以便于使用和管理云上的存储空间,而不是本地服务器存储。

  • 我正在从事IoT项目,一旦运动检测到范围内的任何物体,该项目便会捕获图像数量。因此,请向我发送步骤,以使用nodejs进行AWS s3存储桶集成的配置。

3 个答案:

答案 0 :(得分:1)

在节点服务器上使用S3模块并阅读文档。

var s3 = require('s3');

var client = s3.createClient({
  maxAsyncS3: 20,     // this is the default
  s3RetryCount: 3,    // this is the default
  s3RetryDelay: 1000, // this is the default
  multipartUploadThreshold: 20971520, // this is the default (20 MB)
  multipartUploadSize: 15728640, // this is the default (15 MB)
  s3Options: {
    accessKeyId: "your s3 key",
    secretAccessKey: "your s3 secret",
    // any other options are passed to new AWS.S3()
    // See: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property
  },
});

答案 1 :(得分:0)

尝试

 var params = {
   Bucket: "examplebucket", 
   CreateBucketConfiguration: {
   LocationConstraint: "eu-west-1"
  }
};
s3.createBucket(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response      
});

有关更多信息,请阅读此link

答案 2 :(得分:0)

检查https://docs.amazonaws.cn/en_us/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html上的文档

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

    let repo = numberofrecord[indexPath.row]as! [String] // your datasource

    let delete = UITableViewRowAction(style: .destructive, title: "Delete", handler: {
        act,del in

            let query = "delete from repost where id=\(repo[0])"; // delete the datasource from databases.
            let s = db.dml(query: query)
            if s == true {
                print("media delete")
            }
            else{
                print("not deleted");
            }

            self.numberofrecord.remove(at: indexPath.row) // delete datasource from array.

            self.tbl.beginUpdates()
            self.tbl.deleteRows(at: [indexPath], with: .automatic) // delete row of table.
            self.tbl.endUpdates()

            self.tbl.reloadDataAfterDelay() // Reload the table after some delay.

    })

    return [delete]
}

将创建一个额外的文件。删除括号中的参数。我发现亚马逊的快速入门指南示例创建了一个额外的文件。这种方法是正确的方法。

var s3bucket = new AWS.S3({params: {Bucket: 'test_bucket/sub_bucket'}});