PhilippKrone / react-native-fileupload

Multi-form file upload for react-native
MIT License
157 stars 73 forks source link

not working for s3 #14

Open skyride99 opened 8 years ago

skyride99 commented 8 years ago

Using RN 17. Below is the code.

var obj = { uploadUrl: 'http://makeuroffer.s3.amazonaws.com', method: 'POST', // default 'POST',support 'POST' and 'PUT' headers: { //'contentType': 'image/jpeg', 'Accept': 'application/json', }, fields: { "acl": "public-read" , "Content-Type": "image/" , "key": 'biz/' + 'third.jpg' , "x-amz-meta-tag": '' , "x-amz-meta-uuid": "14365123651274", "bucket": 'makeuroffer' , "x-amz-algorithm": "AWS4-HMAC-SHA256" , "x-amz-credential": data.key + "/" + moment().format('YYYYMMDD') + "/" + 'us-west-2' + "/" + 's3' +"/aws4_request" , "x-amz-date": data['x-amz-date'] , //'20160112T105326Z' "policy": data.policy, "x-amz-signature": data['x-amz-signature'] }, files: [ { //name: 'filename', // optional, if none then filename is used instead filename: 'more.jpg', // require, file name filepath: pic.uri, // require, file absoluete path //filetype: 'audio/x-m4a', // options, if none, will get mimetype from filepath extension }, ] };

FileUpload.upload(obj, function(err, result) {
  debugger;
  console.log('upload:', err, result);
});
skyride99 commented 8 years ago

The err is "Error happened: Bad Request" The android pic.uri is "file:///storage/emulated/0/Pictures/14974007-a01b-42b1-b4b5-dc63e9eff61f.jpg"

timsuchanek commented 8 years ago

Hi @skyride99 , please try my answer here: https://github.com/PhilippKrone/react-native-fileupload/issues/17 and report how it works

skyride99 commented 8 years ago

Yes that is the fix it needs to be 'file'.

timsuchanek commented 8 years ago

Yeah, and the two pull requests contain both the solution ;)

rreusser commented 8 years ago

I had a lot of trouble getting our S3 uploads to work (the usual vague FORBIDDEN error). I eventually added the option to disable multipart uploads and just use a signed request (i.e. PUT instead of POST). It seemed somewhat simpler and was in line with what we were doing otherwise. It's a little rough (must include fields and files keys even though not used) but see: https://github.com/rreusser/react-native-fileupload