gpt4 book ai didi

javascript - 如何将图像保存在特定文件夹 s3 下?

转载 作者:行者123 更新时间:2023-11-29 10:37:44 26 4
gpt4 key购买 nike

我目前可以在 s3 的根存储桶下上传文件,但是我想指定它应该保存到的文件夹。将文件夹名称附加到 url 会产生 405。

上传

$scope.s3upload = function(file) {
Upload.upload({
url: 'https://s3.amazonaws.com/XXX/',
method: 'POST',
data: {
key: file.name,
AWSAccessKeyId: "XXX",
acl: 'public-read',
policy: "XXX",
signature: "XXX",
"Content-Type": file.type != '' ? file.type : 'application/octet-stream',
filename: file.name,
polyfill IE8 - 9
file: file
}
});
}

S3 CORS 配置

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

S3 存储桶策略

{
"Version": "2008-10-17",
"Id": "Policy1397632521960",
"Statement": [{
"Sid": "Stmt1397633323327",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::XXX/*"
}]
}

最佳答案

您应该将文件夹名称指定为中的前缀,即

  key: "folder/" + file.name,
AWSAccessKeyId: "XXX",
acl: 'public-read',
policy: "XXX",
signature: "XXX",
"Content-Type": file.type != '' ? file.type : 'application/octet-stream',
filename: file.name,
polyfill IE8 - 9
file: file

与大多数对象存储实现一样,Amazon S3 文件夹更像是一个概念,而不是实际的资源类型。

关于javascript - 如何将图像保存在特定文件夹 s3 下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34127801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com