我正在使用以下代码将3个不同的图像上传到S3:
AWS.config.update({
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey
});
const s3Stream = require('s3-upload-stream')(new AWS.S3())
function getUploadStrm() {
return s3Stream.upload({
Bucket: awsS3Bucket,
Key: accessKeyId,
ACL: 'public-read',
StorageClass: 'REDUCED_REDUNDANCY',
ContentType: 'binary/octet-stream',
});
}
(我创建了3个上传流,并分别写入每个流)。
这是我得到的信息:
detail => { Location: 'https://staging-media-assets.s3.amazonaws.com/AKIAIRNYI65C5VKWDEDQ',
Bucket: 'staging-media-assets',
Key: 'AKIAIRNYI65XC5VKWDEDQ',
ETag: '"d7165b042c4068477d03341ca75x518e1-1"' }
detail => { Location: 'https://staging-media-assets.s3.amazonaws.com/AKIAIRNYI65C5VKWDEDQ',
Bucket: 'staging-media-assets',
Key: 'AKIAIRNYI65XC5VKWDEDQ',
ETag: '"e325f4cb98e4af408e60e421e37xa4a27-1"' }
detail => { Location: 'https://staging-media-assets.s3.amazonaws.com/AKIAIRNYI65C5VKWDEDQ',
Bucket: 'staging-media-assets',
Key: 'AKIAIRNYI65XC5VKWDEDQ',
ETag: '"8a04422756e20eb9f93718422fx11dad8-1"' }
我的问题是,在返回信息的情况下,我如何定位上传图像的URL?
S3网站上的信息并没有让我明白:
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createMultipartUpload-属性
给定这些响应,您似乎每次都使用相同的Key值,因此每次都覆盖S3上的文件。看起来您将AWS Access密钥作为S3密钥传递,这是不正确的。S3密钥是您正在上传的对象的唯一ID。您需要在传递给s3Stream.upload()
的参数中为key
指定唯一值。您返回的Location
值将是S3上文件的URL。