React-native-fs: Socket is closed issue

Created on 10 Jan 2021  路  3Comments  路  Source: itinance/react-native-fs

when try to upload file it through error socket is closed

Most helpful comment

Try to remove the protocol file:// from the path on Android. It worked for me:

const res = await RNFS.uploadFiles({
  toUrl,
  method: 'POST',
  files: [
    {
      filename,
      filepath: Platform.select({
        android: path.replace('file://', ''),
        ios: path,
      }),
    },
  ],
}).promise

All 3 comments

Got this as well

Try to remove the protocol file:// from the path on Android. It worked for me:

const res = await RNFS.uploadFiles({
  toUrl,
  method: 'POST',
  files: [
    {
      filename,
      filepath: Platform.select({
        android: path.replace('file://', ''),
        ios: path,
      }),
    },
  ],
}).promise

Before you upload files make sure that each file exist. if you are uploading picture. you can preview the image first and remove white/corrupted images before you upload.

Was this page helpful?
0 / 5 - 0 ratings