benjreinhart / react-native-aws3

Pure JavaScript React Native library for uploading to AWS S3
MIT License
399 stars 151 forks source link

fetch instead of XMLHttpRequest #43

Open rickevry opened 7 years ago

rickevry commented 7 years ago

This PR will not be merged, but it shows that there is a bug in how XMLHttpRequest loads a video stream. Instead of uploading the video, it uploads the first frame (as an image).

This is the code that currently does not work:

<MediaPicker groupTypes={'All'} batchSize={25} maximum={15} assetType={'Videos'}           imagesPerRow={3} imageMargin={0} callback={(f)=> this.uploadFile(f[0])}  />

uploadFile(f) {
const file = { uri: f, name: "test.mp4", type: "video/mp4" }
const options = {
  keyPrefix: "uploads/",
  bucket: "xxxxxx",
  region: "eu-west-1",
  accessKey: "xxxxx",
  secretKey: "xxxxx",
  successActionStatus: 201
}

RNS3.put(file, options).then(response => {
  if (response.status !== 201)
    throw new Error("Failed to upload image to S3");
});
}

My implementation uses react-native-fetch-blob and works fine. 

RNS3.putWithFetch(file, options).then(response => {
  if (response.status !== 201)
    throw new Error("Failed to upload image to S3");
});
}
Tzinov15 commented 7 years ago

Hi @rickevry , can you confirm that this PR will result in this library working with video upload as well? I've been using this library for months and had given up on being able to upload videos with it but if this PR fixes that then this is a godsend. Thanks!

bz123 commented 7 years ago

It does work and it uploads the file to s3, but there is no promise returned out of it and you have no way to know if it happened, and the details of the item.