I’m developing an Android application using Xamarin.Android, hence I’m using SendBird’s .net library. I have implemented a function to send a ‘FileMessage’ (image, in particular) from local phone directory path. The issue I’m having is when I’m trying to display the ‘FileMessage’ in ‘OnMessageReceived’ event in the ‘ChannelHandler’. I was able to get the URL of the ‘FileMessage’ in the said event, but I can’t access the stream from the URL.
Here is the function that I use to access the URL:
private byte[] getBitmapFromURL(String src)
{
try
{
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection)url.OpenConnection();
connection.DoInput = true;
connection.Connect();
Stream input = connection.InputStream;
MemoryStream memoryStream = new MemoryStream();
input.CopyTo(memoryStream);
return memoryStream.ToArray();
}
catch (Java.IO.IOException e)
{
e.PrintStackTrace();
return null;
}
}
The function above throws an IOException when it reached connection.InputStream:
{Java.IO.FileNotFoundException: https://file-ap-9.sendbird.com/bcb2d8e2a41a4561b4608e09a8c81313.jpg
at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in :0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in :0
at Java.Net.URLConnection.get_InputStream () [0x0000a] in :0
— End of managed Java.IO.FileNotFoundException stack trace —
java.io.FileNotFoundException: https://file-ap-9.sendbird.com/bcb2d8e2a41a4561b4608e09a8c81313.jpg
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:26)
}
Here are some details from the FileMessage that I could see when I debug my program:
Please let me know if there is any specific way to access the image stream from images uploaded to Sendbird, or if there is anything else I could provide.