react-native-background-upload
react-native-background-upload copied to clipboard
Broken Pipe while trying to upload to S3
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!
Any Udpate on this?
did you get any solution ?
any solution to this problem?? experiencing same issue