How to use the react-native-background-upload.startUpload function in react-native-background-upload

To help you get started, we’ve selected a few react-native-background-upload examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Vydia / ReactNativeBackgroundUploadExample / js / components / Upload.js View on Github external
Upload.getFileInfo(opts.path).then((metadata) => {
      const options = Object.assign({
        method: 'POST',
        headers: {
          'content-type': metadata.mimeType // server requires a content-type header
        }
      }, opts)

      Upload.startUpload(options).then((uploadId) => {
        console.log(`Upload started with options: ${JSON.stringify(options)}`)
        this.setState({ uploadId, progress: 0 })
        Upload.addListener('progress', uploadId, (data) => {
          this.handleProgress(+data.progress)
          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) {
        this.setState({ uploadId: null, progress: null })
        console.log('Upload error!', err)
      })
github rastapasta / foodsharing / src / api / uploader.tsx View on Github external
, uri = config.endpoints[endpoint].uri
      , url = config.host +
              Object.keys(opts).reduce((u, key) => u.replace('{' + key +'}', encodeURIComponent(opts[key])), uri)
      , path =
        file.startsWith('/') ? 'file://' + file :
        file.startsWith('ph://') ? convertLocalIdentifierToAssetLibrary(file.substr(5), 'JPG') :
        file
      , headers = {
        'Accept': 'application/json',
        'User-Agent': config.userAgent,
        'Cookie': `PHPSESSID=${session}; CSRF_TOKEN=${token}`,
        'X-CSRF-Token': token,
        'Content-Type': 'application/octet-stream',
      }

  const uploadId = await Upload.startUpload({
        url,
        method: 'PUT',
        type: 'raw',
        path,
        headers,
        notification: {
          enabled: true
        }
      })
  Upload.addListener('progress', uploadId, data => store.dispatch({type: BASKET_UPLOAD_PROGRESS, payload: data.progress}))
  Upload.addListener('error', uploadId, () =>  store.dispatch({type: REQUEST_ERROR}))
  Upload.addListener('cancelled', uploadId, () =>  store.dispatch({type: REQUEST_ERROR}))
  Upload.addListener('completed', uploadId, () => resolve())
})

react-native-background-upload

Cross platform http post file uploader with android and iOS background support

MIT
Latest version published 2 years ago

Package Health Score

57 / 100
Full package analysis