使用 aws-api s3.upload 在文件位置给出 403 错误
Using aws-api s3.upload gives 403 error on file location
我如何访问 data.Location 这是来自 s3.upload 来自音频源的响应?
现在当我尝试
<audio src"{pathToFile}" ></audio>
我在控制台中收到此错误
GET https://my-buc.s3.amazonaws.com/693v36g6j9o7pdi6qg4gafClean.mp3
403 (Forbidden)
这是我的代码:
const s3 = new AWS.S3({
accessKeyId: process.env.REACT_APP_S3_KEY,
secretAccessKey: process.env.REACT_APP_S3_SECRET
});
const params = {
Bucket: "my-buc", // pass your bucket name
Key: this.state.filename,
Body: this.state.uploadedFile
};
s3.upload(
params,
function(err, data) {
console.log(err, data);
console.log(data.Location);
this.setState({ pathToFile: data.Location }); //extracting data.Location
}.bind(this)
);
my-buc 政策
{
"Version": "2012-10-17",
"Id": "Policy##########",
"Statement": [
{
"Sid": "St##########",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::699######:user/user"
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::my-buc"
}]
}
轻松轻松修复
const params = {
Bucket: "my-buc", // pass your bucket name
Key: this.state.filename,
Body: this.state.uploadedFile
ACL: "public-read" //public read allows you to use the return URL
};
我如何访问 data.Location 这是来自 s3.upload 来自音频源的响应?
现在当我尝试
<audio src"{pathToFile}" ></audio>
我在控制台中收到此错误
GET https://my-buc.s3.amazonaws.com/693v36g6j9o7pdi6qg4gafClean.mp3
403 (Forbidden)
这是我的代码:
const s3 = new AWS.S3({
accessKeyId: process.env.REACT_APP_S3_KEY,
secretAccessKey: process.env.REACT_APP_S3_SECRET
});
const params = {
Bucket: "my-buc", // pass your bucket name
Key: this.state.filename,
Body: this.state.uploadedFile
};
s3.upload(
params,
function(err, data) {
console.log(err, data);
console.log(data.Location);
this.setState({ pathToFile: data.Location }); //extracting data.Location
}.bind(this)
);
my-buc 政策
{
"Version": "2012-10-17",
"Id": "Policy##########",
"Statement": [
{
"Sid": "St##########",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::699######:user/user"
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::my-buc"
}]
}
轻松轻松修复
const params = {
Bucket: "my-buc", // pass your bucket name
Key: this.state.filename,
Body: this.state.uploadedFile
ACL: "public-read" //public read allows you to use the return URL
};