sendFileMessage returns Request failed

I am getting the same issue. When passing a Blob as suggested into sendFileMessage, I get the following error:

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'a.data.name')]
- node_modules/sendbird/SendBird.min.js:6:14434 in value
- node_modules/sendbird/SendBird.min.js:6:18726 in checkRouting$argument_0
- node_modules/sendbird/SendBird.min.js:6:14977 in value
- node_modules/sendbird/SendBird.min.js:6:18566 in value
- node_modules/sendbird/SendBird.min.js:6:58591 in r.upload.progressHandler
- node_modules/sendbird/SendBird.min.js:6:80935 in value
- node_modules/sendbird/SendBird.min.js:6:57933 in value
- node_modules/sendbird/SendBird.min.js:6:176974 in value
- node_modules/sendbird/SendBird.min.js:6:175342 in messageQueue.map$argument_0
- node_modules/sendbird/SendBird.min.js:6:175836 in value
- node_modules/sendbird/SendBird.min.js:6:174357 in value
- node_modules/sendbird/SendBird.min.js:6:178997 in value
- node_modules/sendbird/SendBird.min.js:6:127683 in value
* src/sections/inbox/screens/ChatScreen/index.tsx:137:6 in useCallback$argument_0
- node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
- node_modules/regenerator-runtime/runtime.js:293:29 in invoke
- node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
- node_modules/regenerator-runtime/runtime.js:154:27 in invoke
- node_modules/regenerator-runtime/runtime.js:164:18 in PromiseImpl.resolve.then$argument_0
- node_modules/react-native/node_modules/promise/setimmediate/core.js:37:13 in tryCallOne
- node_modules/react-native/node_modules/promise/setimmediate/core.js:123:24 in setImmediate$argument_0
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:181:14 in _callImmediatesPass
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:441:30 in callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:387:6 in __callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

When adding a name field to the blob object to attempt to fix this, I get the same vague “Request failed” error mentioned in Riyan’s post.

Here’s my code for reference:

       const { uri } = imagePickerResult;
       // Example URI: file:/data/user/0/host.exp.exponent/cache/ExperienceData/PROJ/ImagePicker/85e7df66-4716-4bdb-bd38-867b764f75b1.jpg
       const response = await fetch(uri);
       const blob = await response.blob();

       const params = new SB_INSTANCE.FileMessageParams();
       // sendFileMessage expects a `File` despite the docs saying it expects a `Blob`
       params.file = blob as File;
       params.fileName = 'Test file';
       params.fileSize = blob.size;
       params.mimeType = blob.type;
       params.customType = '';
       params.data = '';

       channel.sendFileMessage(params, cb);

Relevant dependencies:

"expo": "~40.0.0",
"expo-image-picker": "~9.2.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
"sendbird": "^3.0.144"

@jonathan_phipps,

Welcome to the Sendbird Community. I’ve moved your post into its own topic as the one you posted in has been dormant for some time.

Please allow me some time to recreate the problem using the sample code you provided.

Thanks,
Tyler

Hi Tyler, unfortunately we are under tight deadlines and have decided to host images ourselves due to this issue and its lack of response.

hi Tyler have your reproduced this issue?. we are experiencing the same issue when sending a blob type

this code works for my react-native app

        const sb = SendBird.getInstance();
        const params = new sb.FileMessageParams();

        let source: IFile = {
          uri: file.uri,
          name: file.fileName,
          type: file.type,
        };

        params.file = source;
        if (file.fileName) {
          params.fileName = file.fileName;
        }
        if (file.fileSize) {
          params.fileSize = file.fileSize;
        }
        if (file.type) {
          params.mimeType = file.type;
        }
        params.thumbnailSizes = [{ maxWidth: 200, maxHeight: 200 }];

        channel.sendFileMessage(params, message => {
          resolve(message);
        });
1 Like

This solution works for me.
Thanks