pgarciacamou
pgarciacamou

Reputation: 1732

Sendbird send image file

I'm going through the JavaScript documentation for Sendbird and although the method to send files is there, there is no explanation on what each argument has to be or the different options.

channel.sendFileMessage(FILE, FILE_NAME, FILE_TYPE, FILE_SIZE, CUSTOM_DATA, function(message, error){
    if (error) {
        console.error(error);
        return;
    }
    console.log(message);
});

I found this stackoverflow question that guided me a bit, but I'm still unable to send a file.

Has someone been able to send an image with sendbird using JavaScript? I'm looking for a working JS example and/or documentation about the multiple options available.

Upvotes: 2

Views: 3111

Answers (2)

Milan
Milan

Reputation: 152

To send file message, you only need one of the argument in the function, the one which defines your source. The other arguments is not neccasary for the basic function.

channel.sendFileMessage(File, function(message, error) {
  if (error) {
    console.log(error);
    return;
  }

And for the source File, you need to just define the path to it either locally or globally. Hope it was helpful.

Here is a useful link: https://github.com/smilefam/SendBird-JavaScript/blob/master/react-native-sample/SendBirdReactNativeSample/src/pages/chat.js

Upvotes: 3

Jin Ku
Jin Ku

Reputation: 196

In React Native, you should pass something like

{ uri: 'file://p/q/a.jpg' name: 'a.jpg' type: 'image/jpg' }

to sendFileMessage method.

Here's a sample code you should take a look at.

https://github.com/smilefam/SendBird-JavaScript/blob/master/react-native-sample/SendBirdReactNativeSample/src/pages/chat.js#L178

Upvotes: 2

Related Questions