How to send the mutiple images?

Hello, Sendbird community we have requirement that user can select & send the 5 attachments at once rater than individual attachment one at a time. So please let us know how we achieve this?

Hello @Development_Account !

You can send multiple files through BaseChannel.sendFileMessages.
Here’s the link for reference, please check it out!

@Jerry_Jeon Thanks for providing the information.

We have implemented the same BaseChannel.sendFileMessages and then we are calling the MessageCollection.appendMessage(message); method.

Also we setting the BaseChannel.SendFileMessagesHandler listener to the BaseChannel.sendFileMessages we are calling the below methods on,

public void onSent(FileMessage fileMessage, SendBirdException e) {
MessageCollection.handleSendMessageResponse(fileMessage, e);
MessageCollection.fetchAllNextMessages(null);
}
call back.

After that in the MessageCollectionHandler
public void onSucceededMessageEvent(MessageCollection collection, final List messages, final MessageEventAction action) {

}

callback even though message is different & image URL is different we are getting the same image thumbnail. Please let me know why this happens?

Hi @Development_Account,

I need some clarification to dig further.

  1. Could you confirm you’re calling below methods in onSent() from the BaseChannel.sendFileMessages()? Asking since BaseChannel.sendFileMessages() (with s at the end for sending multiple files) takes SendFileMessagesHandler which only has onResult(SendBirdException) callback, not the onSent(FileMessage, SendBirdException) callback.
public void onSent(FileMessage fileMessage, SendBirdException e) {
MessageCollection.handleSendMessageResponse(fileMessage, e);
MessageCollection.fetchAllNextMessages(null);
}
  1. Could you explain a bit more when you said MessageCollectionHandler#onSucceededMessageEvent(MessageCollection collection, final List messages, final MessageEventAction action) is giving you different message/thumbnail url?

Could you post or send me a dm of your code snippet of when you send multiple file messages with the handling inside the callback and the debug logs of what you received (maybe just print some logs of List inside the MessageCollectionHandler#onSucceededMessageEvent)?

@hoons

Point # 1 :- No we are not calling BaseChannel.sendFileMessages() inside the onSent().

Point #2 :- We are trying to send 3 images and those are sent successfully as well. But after that in the MessageCollectionHandler

public void onSucceededMessageEvent(MessageCollection collection, 
                                   final List<BaseMessage> messages, 
                                   final MessageEventAction action) {
        }

In the List<BaseMessage> messages the each message has the URL, Even thought the all 3 message has different URL. But in the message list UI first image is loaded 3 times instead of once.

Hi @Development_Account

Does this mean that onSucceededMessageEvent gives you 3 messages with all different urls, say message1=url1, message2=url2, message3=url3, but when you draw it in your message list UI, all three messages are loaded with url1 only?

@hoons Yes correct that is issue we are facing.

Hi @Development_Account,

Thanks for clarifying the issue.
It seems like the SDK is delivering correct message objects but may be a bug in the UI side.
Could you check on your code related to recycler view where you bind the message objects and see if correct message objects are being drawn?

@hoons I checked the code related to the recycler view where we bind the message objects & it is proper. It is the issue with the URL that SDK is giving to the consumer end.

Below mentioned two messages are sent through BaseChannel.sendFileMessages methode together,

------------------------ Message 1 ------------------------
The actual image uploaded is “C.png” which is attached below
C

In the message object, we are getting the below-mentioned URL.

name = "C.png"
type = "image/png"
url = "https://file-us-3.sendbird.com/84422da3f4db45d984792767c4c3a4f4.png?auth=Q5-uHN_JWEaqNmy1UTj2g_bpAu7u7l6UO0HXLQAQtNaRZNHo-mmNVV6fPJe2qhDQPWBlc9hpxb17vsnW7Med3Q"

------------------------ Message 2 ------------------------
The actual image uploaded is “D.png” which is attached below
D

In the message object, we are getting the below-menoned URL.

name = "D.png"
type = "image/png"
url = "https://file-us-3.sendbird.com/8d24c32845fb4e2f86b3a2db86908868.png?auth=Q5-uHN_JWEaqNmy1UTj2g_bpAu7u7l6UO0HXLQAQtNaRZNHo-mmNVV6fPJe2qhDQ3rqCOciBoZXqFCrGlMBIzA"

If you hit the URL in the browser & download the file by adding .png to the file name both URL has the same image which is "D.png", even though the URL is different & image sent is different.

So please check & revert me back, If any other information is required.

@hoons Any update on this?

@Development_Account

Sorry for the late response.

If the SDK gave two different messages with two different urls, but which are actually the same image, we must check if the correct image was sent via the SDK.
Is this issue reproducible on your end? It would be good to check on the request side if two different files are being sent.

@hoons I am able to reproduce it always we are passing the correct info to SDK, I am pretty sure about it. Please let me know how to check on the request?

@Development_Account

I have tested with out sample and it’s seems to be working as intended. This is the code I’ve used, and all sent file messages are received from MessageCollectionHandler.onSucceededMessageEvent() with different file urls.

List<File> fileList; // List of your selected files.
List<FileMessageParams> paramsList = new ArrayList<>();

for (File file : fileList) {
    FileMessageParams params = new FileMessageParams(file);
    params.setFileName(name);
    params.setMimeType(mime);
    params.setFileSize(size);
    params.setThumbnailSizes(thumbnailSizes);
    paramsList.add(params);
}

channel.sendFileMessages(paramsList, new BaseChannel.SendFileMessagesHandler() {
    @Override
    public void onResult(SendBirdException e) {
    }

    @Override
    public void onSent(FileMessage fileMessage, SendBirdException e) {
        Log.d("Sample", "Sent: " + fileMessage);
        messageCollection.handleSendMessageResponse(fileMessage, e);
    }
});

Could you double check you’re setting a different File object in each of your FileMessageParams when you call the channel.sendFileMessages()?

If you still face the same issue and unable to debug it, it’d be better if you file a help ticket to us to get more direct support on this case.

Thank you.