I cannot sendFileMessage with RN getting error 800220

Hi,
I want to send a file and host it on SendBird’s Server, so i pass the file from DocumentPicker, convert to blob, then convert to File

Here is piece of my code:
selectPhotoTapped = async () => {
const options = {
type: [DocumentPicker.types.images, DocumentPicker.types.video, DocumentPicker.types.pdf],
readContent: true,
// copyTo: ‘cachesDirectory’,
}

try {
  const doc = await DocumentPicker.pick(options)
  const response = await fetch(doc.uri)
  const blob = await response.blob()
  const sb = SendBird.getInstance()
  const params = new sb.FileMessageParams()
  const { groupChannel } = this.state
  const file = new File([blob], doc.name)
  console.log(file)
  params.file = file
  params.fileName = doc.name
  params.fileSize = doc.size
  params.data = ''
  // params.thumbnailSizes = [
  //   { maxWidth: 100, maxHeight: 100 },
  //   { maxWidth: 200, maxHeight: 200 },
  // ] // Add the maximum sizes of thumbnail images (allowed number of thumbnail images: 3).
  params.mimeType = doc.type
  params.customType = 'PARTICIPANT_CHAT'
  // params.metaArrayKeys = ['linkTo', 'itemType']
  params.pushNotificationDeliveryOption = 'default'
  groupChannel.sendFileMessage(params, (fileMessage, error) => {
    console.log(fileMessage)
    if (error) {
      console.log(error)
      return
    }
    let tempMessages = Object.assign([], this.state.messages)
    tempMessages = [...[fileMessage], ...tempMessages]
    this.setState({ messages: tempMessages, textMessage: '' }, () => {
      if (this.state.messages.length > 0)
        this.flatList.scrollToIndex({ index: 0, animated: true })
    })
  })
} catch (e) {
  console.log(e)
}
  }

Here’s the error i get

0.2.2꞉8081/App/Containers/Discussion/DiscussionScreen.bundle?platform=android&dev=true&minify=false&modulesOnly=true&runModule=false&shallow=true:360

i: Request failed.
at b.value (/[censored]/node_modules/sendbird/SendBird.min.js:6:13712)
at /[censored]/node_modules/sendbird/SendBird.min.js:6:15695
at tryCallOne (/[censored]/node_modules/promise/setimmediate/core.js:37:12)
at /[censored]/node_modules/promise/setimmediate/core.js:123:15
at /[censored]/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:289:18
at _callTimer (/[censored]/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:7)
at _callImmediatesPass (/[censored]/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:7)
at Object.callImmediates (/[censored]/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:12)
at MessageQueue.__callImmediates (/[censored]/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:12)
at /[censored]/.vscode/.react/index.bundle:5326:18 {name: ‘SendBirdException’, code: 800220, stack: ‘SendBirdException: Request failed.
at b.v…/.vscode/.react/index.bundle:5326:18’, message: ‘Request failed.’}

I’ve tried pass blob file to params.file, but here’s another error:

TypeError: Cannot read property ‘name’ of und…mobile/.vscode/.react/index.bundle:242110:69)’, message: ‘Cannot read property ‘name’ of undefined’}

for additional info, here is my package.json:

"react-native": "0.61.5",
"react-native-document-picker": "^4.1.0",
"sendbird": "^3.0.138"

Please help in advance.
Thanks!

Hi Riyan,

Could you change like below?

... 
const blob = await response.blob() 
... 
params.file = blob 
...

You can remove this line:
const file = new File([blob], doc.name)

A post was split to a new topic: sendFileMessage returns Request failed