react-native-background-upload icon indicating copy to clipboard operation
react-native-background-upload copied to clipboard

Broken Pipe while trying to upload to S3

Open jaimish11 opened this issue 3 years ago • 3 comments

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?

  • OS - Android 11
  • React Native version - 0.64.2
  • React Native Background Upload version - 6.4.0
  • I see the upload notification but it doesn't show or do anything.
  • S3 bucket has PutObject, GetObject and DeleteObject permissions
  • Android build file SDK details:
targetSdkVersion = 23
compileSdkVersion = 23   
buildToolsVersion = '23.0.2'

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

jaimish11 avatar Aug 20 '21 19:08 jaimish11

Any Udpate on this?

hamzaajaved avatar Feb 09 '23 20:02 hamzaajaved

did you get any solution ?

Hidayat112 avatar Feb 14 '24 18:02 Hidayat112

any solution to this problem?? experiencing same issue

ArsalanReal avatar Mar 22 '24 11:03 ArsalanReal