Ad
Using Aws-api S3.upload Gives 403 Error On File Location
How I can access data.Location which is a response from s3.upload from an audio src?
Right now when I try
<audio src"{pathToFile}" ></audio>
I get this error in the console
GET https://my-buc.s3.amazonaws.com/693v36g6j9o7pdi6qg4gafClean.mp3
403 (Forbidden)
Here is my code:
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 policy
{
"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"
}]
}
Ad
Answer
Easy Easy Fix
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
};
Ad
source: stackoverflow.com
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?
Ad