Good day everyone! I would like to send image file(less than 4mb) to other online user. Sending with only text message is no problem.. but when trying to send with file keeps disconnecting. Can you have a moment to look into my the codes below.
Please let me know where I'm doing it wrong. Thanks for the help.
B4X:
Public Sub SendMessage(Body As String)
If connected Then
client.Publish2("all", CreateMessage(Body), 0, False)
End If
End Sub
Private Sub CreateMessage(Body As String) As Byte()
Dim m As Message
m.Initialize
m.Body = Body
Log(m.Body)
If Main.gvFileName.Length > 1 Then
If File.Exists(File.DirRootExternal & "/Download" , Main.gvFileName) Then
Main.gvFolderPath = File.DirRootExternal & "/Download"
Dim b() As Byte = File.ReadBytes(Main.gvFolderPath,Main.gvFileName)
m.Body = Body
m.From = currentName
m.filename = Main.gvFileName
m.Image = b
Log("with file attached")
End If
Else
m.Body = Body
m.From = currentName
Log("only message")
End If
Log(">> " & m.Body & " " & m.From & " " & m.filename & " L:" & m.Image.Length)
Main.gvFileName = ""
'client.Publish2("all", serializator.ConvertObjectToBytes(m), 0, True)
Return serializator.ConvertObjectToBytes(m)
End Sub
Please let me know where I'm doing it wrong. Thanks for the help.