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
721 stars 325 forks source link

Broken Pipe while trying to upload to S3 #279

Open jaimish11 opened 2 years ago

jaimish11 commented 2 years ago

What I'm trying to do - upload an image to S3 What does my code look like?

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

const upload = async (uri) => {
    if(Platform.OS === "ios"){
        uri+='file://' + uri
    }
    else if(Platform.OS === "android"){
        uri = uri.replace('file://', '')
    }
    const fileInfo = await Upload.getFileInfo(uri);
    let options = {
        url: 'https:/s3_bucket_name.s3.s3_region.amazonaws.com/'+fileInfo.name,
        path: uri,
        method: 'POST',
        type: 'multipart',
        field:'uploaded_media',
        headers: {
          'content-type': fileInfo.mimeType, 
          'content-length': fileInfo.size.toString()
        },
        parameters:{
            ...S3Policy.generate({
                bucket: 's3_bucket_name',
                region: 's3_region_name',
                accessKey: 's3_Access_key',
                secretKey: 's3_secret_key',
                successActionStatus: 201,
                key: fileInfo.name,
                date: new Date(),
                contentType: fileInfo.mimeType,
              })
        }
    }
    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)
    })
}

Logs from my console?

 LOG Upload started
 LOG  Progress: 0%
 LOG  Progress: 0%
 LOG  Progress: 0%
 LOG  Error: Broken pipe%

Extra info?

Been at this for days. Any help would be appreciated!

hamzaajaved commented 1 year ago

Any Udpate on this?

Hidayat112 commented 5 months ago

did you get any solution ?

ArsalanReal commented 4 months ago

any solution to this problem?? experiencing same issue