如何使用nodejs在AWS中创建新的S3桶?
为了便于使用和管理云端存储空间,我需要将大量的图像文件上传到s3存储桶上,而不是本地服务器存储空间。
发布于 2018-11-12 07:27:07
在节点服务器上使用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
},
});发布于 2018-11-12 07:26:49
尝尝这个
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
});有关更多信息,请阅读此链接
发布于 2018-11-13 06:04:30
检查us/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html上的文档
var s3bucket = new AWS.S3({params: {Bucket: 'test_bucket/sub_bucket'}}); 将创建一个额外的文件。取出括号中的参数。我发现Amazon的快速启动指南示例创建了一个额外的文件。这样做是正确的。
// Create a bucket using bound parameters and put something in it.
var s3bucket = new AWS.S3();
s3bucket.createBucket(function() {
var params = {Bucket: 'bucket/sub-bucket', Key: 'file_name1', Body: 'Hello!'};
s3bucket.putObject(params, function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
res.writeHead(200, {'Content-Type':'text/plain'});
res.write("Successfully uploaded data to bucket/sub-bucket/");
res.end()
}
});
});https://stackoverflow.com/questions/53257488
复制相似问题