Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working for me, status 400 #5

Open
satyagupta opened this issue May 26, 2016 · 2 comments
Open

Not working for me, status 400 #5

satyagupta opened this issue May 26, 2016 · 2 comments

Comments

@satyagupta
Copy link

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);

let opts = {
  url: 'https://' + s3_opts.bucket + '.s3.amazonaws.com/',
  files: uploadFiles,
  method: 'POST',
  params: {
    key: Date.now(),
    acl: s3_opts.acl,
    'X-Amz-Signature': p.signature,
    'x-amz-credential': p.credential,
    'X-Amz-Algorithm': 'AWS4-HMAC-SHA256',
    'X-Amz-Date': p.date + 'T104657Z',
    'Content-Type': 'image/jpeg',
    'policy': p.policy,
    'success_action_status': '201',
    // 'x-amz-meta-uuid': '14365123651274'
  }
};

//console.log(opts);

RNUploader.upload( opts, (err, response) => {
    if( err ){
        console.log(err);
        return;
    }
    console.log(response);
    /*
    let status = response.status;
    let responseString = response.data;
    let json = JSON.parse( responseString );

    console.log('upload complete with status ' + status);*/
});`
@satyagupta
Copy link
Author

@lifuzu Please reply

@phoenixbox
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants