I want to send a file message and for doing so i am using Send a message | Chat Platform API | Sendbird Docs JS chat SDK.
The params:
const params = {
fileUrl: MSG?.uri,
fileName: MSG?.fileName,
fileSize: MSG?.fileSize,
thumbnailSizes: [
{ maxWidth: 100, maxHeight: 100 },
{ maxWidth: 200, maxHeight: 200 },
],
mimeType: MSG?.type,
customType: "",
mentionType: "users",
mentionedUserIds: [],
};
ticket.channel.sendFileMessage(params, (message, error) => {
if (error) {
console.log("e", error);
}
console.log("message", message);
});
The selected file object is:
Here’s the error that i get:
I aslo tried to send a splash image url to verify if this error is due to file uri, but it threw the same error for the latter.
What am i missing or doing the wrong way here?
Hi @Namrata_Jain , what version of Chat SDK are you using?
import {} from 'sendbird'; // v3
import {} from '@sendbird/chat'; // v4
FYI, If you are using sendbird-desk
SDK, the Chat SDK version is v3.
we are using ticket instance passed from ticketChannel,
const sendCustomerInput = (
MSG,
ticket,
setCustomerInputText,
isFileMessage
) => {
if (isFileMessage) {
ticket.channel.sendFileMessage(
{
file: {
size: MSG?.fileSize,
uri: MSG?.uri,
type: MSG?.type,
name: MSG?.fileName,
},
},
(message, error) => {
if (error) {
console.log("e", error);
}
console.log("message", message);
}
);
}
we are sending the ticket instance from other component to this above function, and trying to send the file message using
ticket.channel.sendFileMessage()
And we are following this as per the documentation.
Guides for quick and easy integration of Sendbird Chat, Calls and Desk for iOS, Android, JavaScript, Unity, .NET and Platform API.
We could not understand the above answer which is related to the version of sendbird chat, we are unable to understand in what context is it related to the question asked by us.
Sendbird chat SDK has two versions: v3 and v4.
The implementation of sending file messages varies depending on the SDK version being used. Therefore, it isn’t easy to provide an accurate answer based solely on the current question.
The format of the code and logs you provided does not seem to match the version mentioned in the document you followed, so knowing the SDK version you are using will help me provide the correct response.
Our chat SDK version is v4,
"@sendbird/chat": "^4.7.2",
"sendbird-desk": "^1.0.23"
As mentioned above, the v3 chat SDK is used within sendbird-desk.
Please try the following:
import SendBird from 'sendbird';
const sb = SendBird.getInstance();
const params = new sb.FileMessageParams();
params.file = {
size: MSG?.fileSize,
uri: MSG?.uri,
type: MSG?.type,
name: MSG?.fileName,
};
ticket.channel.sendFileMessage(params, (message, error) => {
if (error) {
console.log("e", error);
}
console.log("message", message);
});
const params = new sendbird.FileMessageParams();
params.file = {
size: result.size,
uri: result.uri,
name: result.name,
type: result.type,
};
dispatch({ type: 'start-loading' });
channel.sendFileMessage(params, (message, err) => {
dispatch({ type: 'end-loading' });
if (!err) {
dispatch({ type: 'send-message', payload: { message } });
} else {
setTimeout(() => {
dispatch({ type: 'error', payload: { error: 'Failed to send a message.' } });
}, 500);
}
});
Thank you @Airen_Kang , this worked for us, it’s working as expected now.
1 Like
Hey @Airen_Kang we also want to generate thumnails for our file messages, we tried to follow your documentation but failed to achieve it.
The documentation we followed to achieve it is here: Generate thumbnails of a file message | Chat JavaScript SDK | Sendbird Docs
the updated params we are sending is:
const params = new sendbirdInstance.FileMessageParams();
params.file = {
size: MSG?.fileSize,
uri: MSG?.uri,
type: MSG?.type,
name: MSG?.fileName,
thumbnailSizes: [
{ maxWidth: 100, maxHeight: 100 },
{ maxWidth: 200, maxHeight: 200 },
],
};
but in our response we get no thumbnails.
what are we missing here?