Vydia / react-native-background-upload

Upload files in your React Native app even while it's backgrounded. Supports Android and iOS, including camera roll assets.
MIT License
723 stars 330 forks source link

Upload error while uploading to s3 bucket #215

Closed HarshMB closed 4 years ago

HarshMB commented 4 years ago

When i will upload image, it will show progress 0% to 100% after that it will display "Error : Upload error" I am uploading file like this:

     import Upload from 'react-native-background-upload'
     import { S3Policy } from '../../node_modules/react-native-aws3/src/S3Policy';

     const options = {
              type: 'multipart',
              method: 'POST’,
             url: “S3 bucket URL”
             field: 'file',
             path: filePath,
             parameters: {
                           ...S3Policy.generate({
                            bucket: ‘bucket name,
                            region: ‘bucket region’,
                            accessKey: ‘key’,
                             secretKey: ‘secKey’,
                            successActionStatus: 201,
                            key: ‘fileName’,
                            date: new Date(),
                            contentType: file.type,
                          }),
                     },
         };

        const uploadId = await Upload.startUpload(options)

        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) => {
                          console.log('Completed!')
        })

Output: Progress: 0% Progress: 31% Progress: 72% Progress: 100% Error: Upload error

matamicen commented 3 years ago

@HarshMB we fixed that problem changing the pre signed function to allows more fileSize ... I don't if it is your case but it was ours.

rahulnainwal commented 3 years ago

@HarshMB how you solved this issue. @matamicen where is pre signed function, can you please explain it.

matamicen commented 3 years ago

@rahulnainwal check this

Hope it helps :)

rahulnainwal commented 3 years ago

Thank you @matamicen, i am getting this issue because of wrong access key and secret key.