I,m using Smack to upload avatar. It takes long time and most of that time it times out (sometimes even 2min is not enough). Is there a way I can improve on that? Is there any other way to quickly upload avatar?
I know I can have just my own http service serving avatars, but I'm not willing to go that route right now. Fetching VCard avatar is very quick.
I use Smack 4.3.0 and Smack Logs are found here: https://pastebin.com/dQbSEpmJ
Here is the code I use:
fun setPhoto(path: String) = viewModelScope.launch(Dispatchers.IO) {
try {
val file = File(path)
val vCardMgr = VCardManager.getInstanceFor(connection)
val vCard = vCardMgr.loadVCard()
vCard.setAvatar(Base64.encodeToString(file.readBytes(), Base64.DEFAULT), FileUtils.getMimeType(path))
vCardMgr.saveVCard(vCard)
} catch (e: Exception) {
launch(Dispatchers.Main){
Toast.makeText(chatApp.applicationContext, e.message, Toast.LENGTH_LONG).show()
}
}
}
I found that testing with openfire, the file size was so bing which in turn caused the Stanza to be so hughe that it crashed the server. That was confirmed by Guus (Ignite Realtime guy) and here I quote him:
Openfire has a (configurable) maximum stanza size limit. I think it’s on 2MB. Note that when you base64 encode binary data, the encoded result will be a lot larger than the unencoded original. I suggest that you reduce the image size in your vcard, or use another mechanism to exchange the data.
So compressing the image solved the issue