
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
react-native-background-upload
Advanced tools
Cross platform http post file uploader with android and iOS background support
The only React Native http post file uploader with android and iOS background support. If you are uploading large files like videos, use this so your users can background your app during a long upload.
npm install react-native-background-upload
react-native link react-native-background-upload
Add Files to <...>
node_modules
➜ react-native-background-upload
➜ ios
➜ select VydiaRNFileUploader.xcodeproj
VydiaRNFileUploader.a
to Build Phases -> Link Binary With Libraries
Add the following lines to android/settings.gradle
:
include ':react-native-background-upload'
project(':react-native-background-upload').projectDir = new File(settingsDir, '../node_modules/react-native-background-upload/android')
Add the compile line to the dependencies in android/app/build.gradle
:
dependencies {
compile project(':react-native-background-upload')
}
Add the import and link the package in MainApplication.java
:
package com.vydia // <-- add this import
public class MainApplication extends Application implements ReactApplication {
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new UploaderReactPackage() // <-- add this line
);
}
}
import Upload from 'react-native-background-upload'
const options {
url: 'https://myservice.com/path/to/post',
path: 'file://path/to/file/on/device',
method: 'POST',
headers: {
'my-custom-header': 's3headervalueorwhateveryouneed'
}
}
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('completed',uploadId, (data) => {
console.log(`Completed!`)
})
}).catch(function(err) {
console.log('Upload error!',err)
});
Does it support iOS camera roll assets?
No, they must be converted to a file asset. The easist way to tell is that the url should always start with 'file://'. If not, it won't work. Things like react-native-image-picker provide you with both. PRs are welcome for this.
Does it support multiple file uploads?
Yes and No. It supports multiple concurrent uploads, but only a single upload per request. That should be fine for 90%+ of cases.
Why should I use this file uploader instead of others that I've Googled like react-native-uploader?
This package has two killer features not found anywhere else (as of 12/16/2016). First, it works on both iOS and Android. Others are iOS only. Second, it supports background uploading. This means that users can background your app and the upload will continue. This does not happen with other uploaders.
Thanks to:
android-upload-service It made Android dead simple to support.
MIME type from path on iOS Thanks for the answer!
FAQs
Cross platform http post file uploader with android and iOS background support
The npm package react-native-background-upload receives a total of 2,616 weekly downloads. As such, react-native-background-upload popularity was classified as popular.
We found that react-native-background-upload demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.