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

Uploading Videos to S3 uploads immediately, but does not upload correclty #310

Open
onsiteUDA opened this issue Aug 3, 2022 · 1 comment

Comments

@onsiteUDA
Copy link

Updated to v6.5.1 Videos from camera roll on IOS were being uploaded to S3 instantly, the file seemed to be there in the bucket, however previewing/downloading the file uploaded would not play as if it had been corrupted. Photos work fine they show up as intended

       const access = new Credentials({
           accessKeyId: myKeyID,
           secretAccessKey: mySecretAccessKey
         });


         const s3 = new S3({
           credentials: access,
           region: 'us-west-2',
           signatureVersion: 'v4',
         });

         const s3Params = {
           Bucket:myBucket,
           Key: image.s3key,
           Expires: 900,
           ContentType: mimeType,
           ACL: 'public-read',
         };

         let url = s3.getSignedUrl('putObject', s3Params);
         options = {
           type: 'raw',
           method: 'PUT',
           headers: {
             'content-length': image.size.toString(),
             accept: mimeType,
           },
           url: url, 
           field: 'file',
           path:  path,
           // Below are options only supported on Android
           notification: {
             enabled: true,
             onCompleteTitle: 'File uploaded successfully',
             onErrorTitle: 'File failed to upload',
           },
         };


Upload.startUpload(options).then((uploadId) => {
 console.log('Upload started')
 Upload.addListener('progress', uploadId, (data) => {
   console.log(`Progress: ${data.progress}%`)
 })
 Upload.addListener('error', uploadId, (data) => {
   console.log(`Error: ${data.error}%`)
 })
 Upload.addListener('cancelled', uploadId, (data) => {
   console.log(`Cancelled!`)
 })
 Upload.addListener('completed', uploadId, (data) => {
   // data includes responseCode: number and responseBody: Object
   console.log('Completed!')
 })
}).catch((err) => {
 console.log('Upload error!', err)
})

Attempted to use Post instead using the following

 options = {
            type: 'multipart',
            method: 'POST',
            headers: {
              'content-type': mimeType, 
              'content-length': image.size.toString(),
            },
            url: myURLPost,
            field: 'file',
            path: path,
            parameters: {
              ...S3Policy.generate({
                bucket: myBucket,
                region: 'us-west-2',
                accessKey: myKey
                secretKey: mySecrectAccessKey,
                successActionStatus: 201,
                key: image.s3key,
                date: new Date(),
                contentType: mimeType,
              }),
            },
            // Below are options only supported on Android
            notification: {
              enabled: true,
              onCompleteTitle: 'File uploaded successfully',
              onErrorTitle: 'File failed to upload',
            },
          };

It also had the same outcome.

I then proceeded to downgrade back to where I was (6.2.0) since it was working then. The first method used works for photos as intended but not for the videos; however, the second method used, correctly uploads the video to S3 as they are in the bucket and can be previewed/downloaded correclty

@He1nr1chK
Copy link

He1nr1chK commented May 8, 2023

Hi @onsiteUDA,

Don't know if I am too late, and I also don't know if this might solve your problem but I encountered something similar. In my case files with whitespace in the file name would show that it was finished uploading but on S3 showed 0kb. I used react-native-document-picker & expo-file-system. My solution was to do the following:

const { extension } = await Upload.getFileInfo(filePath);
  localPath = `${FileSystem.documentDirectory}${nameWithNoWhitespace}.${extension}`;
  await FileSystem.copyAsync({
    from: filePath,
    to: localPath,
});

Hope this helps someone!

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