Open satyagupta opened 8 years ago
@lifuzu Please reply
@satyagupta
The key should be a bucket path location like uploads/
or something. If you want it nested to user for a date you could use moment.
import moment from 'moment';
const timeArray = moment().utc().format('L').split('/');
const year = timeArray[2];
const month = timeArray[0];
const day = timeArray[1];
const key = `uploads/${USER_ID}/${year}/${month}/${day}/`;
That way all of an the uploads for a user, can be found under their id and the target date.
Also I think the expires key might be of type Integer and not Date.
So 60000
might be the right value and then AWS will take care of creating the time that says Date.now() +60000
I keep getting status 400 with following response.
<?xml version="1.0" encoding="UTF-8"?>\n<Error><Code>InvalidArgument</Code><Message>Malformed Unicode code sequence in the field.</Message><ArgumentName>formField</ArgumentName><RequestId>CA9372E2E9C1B13C</RequestId><HostId>pVNYeynJARTc5TCf/Gk9MPiY0bgaPpre8Fade6lgbx/aUbUm26X4LCfkXershgXwgDIFDhA9to0=</HostId></Error>
Am i missing anything?
Complete code:
`uploadFiles.push(this.state.files[i]); let s3_opts = { bucket: 'bridalbible', region: 'us-east-1', key: 'YYY', secret: 'XXXX', type: 'image/jpeg', path: 'profile/', acl: 'public-read', expires: new Date(Date.now() + 60000), length: 10485760, // 10M as maximal size }; let p = s3_policy(s3_opts); // console.log(p.policy); // console.log(p.signature);