Upload File With RNFS for ios and Andorid (RNCamera) React Native

July 12, 2022

Upload File With RNFS for ios and Andorid (RNCamera) React Native

Upload File With RNFS for ios and Andorid (RNCamera) React Native

const realPath = Platform.OS === 'ios' ? data.uri.replace('file://', '') : data.uri;
 const Filedata = [
    {
       name: 'file',
       filename : 'avatar.png',
       type:'image/png',
       data: RNFetchBlob.wrap(decodeURIComponent(realPath)),
    },
    {name: 'bla', data: 'bla'}
  ]
  RNFetchBlob.fetch('POST', GLOBALS.BASE_URL + 'User/UploadImage', {
    Authorization : 'Bearer ' + store.response.token.token + '',
    'Content-Type' : 'multipart/form-data',
  },
  Filedata
  ).then((resp) => {
   console.info(resp)
  }).catch((err) => {
    console.info(err)
  })

Written by Manoj Bhardwaj who lives and works in Dharamshala Himachal Pradesh (India). My stackoverflow