Error in uploading image in open channel in Android app

Hello,

I am getting an error of “Not a member” while uploading an image in the open channel.
Below are the error logs I am getting while uploading an image.

2020-12-17 18:13:55.516 7039-8006/com.contap.android E/SendBird: [18:13:55.515 
SocketManager:reconnectInternal():526] -- reconnect fail retry count = 1 message : null
2020-12-17 18:13:55.521 7039-8006/com.contap.android E/SendBird: [18:13:55.521 
SocketManager:reconnectInternal():522] -- reconnect interrupted retry count = 2
2020-12-17 18:13:55.594 7039-8006/com.contap.android E/SendBird: [18:13:55.593 
SocketManager:reconnectInternal():526] -- reconnect fail retry count = 1 message : null
2020-12-17 18:13:55.598 7039-8006/com.contap.android E/SendBird: [18:13:55.597 
SocketManager:reconnectInternal():522] -- reconnect interrupted retry count = 2
2020-12-17 18:13:55.711 7039-8006/com.contap.android E/SendBird: [18:13:55.711 
SocketManager:reconnectInternal():526] -- reconnect fail retry count = 1 message : null
2020-12-17 18:13:55.714 7039-8006/com.contap.android E/SendBird: [18:13:55.714 
SocketManager:reconnectInternal():522] -- reconnect interrupted retry count = 2
2020-12-17 18:13:56.852 7039-7039/com.contap.android E/uploadImageToSendBird(): 
SendBirdException{code=900020, message=Not a member.}

I am using latest Android SDK version: ‘com.sendbird.sdk:sendbird-android-sdk:3.0.152’

I have followed the open channel file upload code from your document.

Let me know if you require more details.

Thanks!
Rakesh

Hello! You need to first ENTER the channel

Hello,

I have already entered the channel. I can get all the messages of the channel but while sending the image I am getting the error.

Just in case, make sure you asked for the correct permissions:

    private void checkAppPermissions() {
        if (ActivityCompat.checkSelfPermission(ChatActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(ChatActivity.this, new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE} , PICK_FROM_GALLERY);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == PICK_FROM_GALLERY) {
            Toast.makeText(mContext, "Permission granted", Toast.LENGTH_LONG).show();
        }
    }

This is an example for sending a file but from my project resources. Maybe it helps…

private void sendFileUrlMessageToSendbird() {

        // Make sure you have a file called "image.jpg" in your RAW folder
        InputStream in = getResources().openRawResource(R.raw.image);
        File f = new File(getCacheDir(), "image.jpg");
        copyInputStreamToFile(in, f);

        FileMessageParams params = new FileMessageParams(f)
                .setFileName(f.getName());

        FileMessage fileMessage = mChannel.sendFileMessage(params, new BaseChannel.SendFileMessageWithProgressHandler() {
            @Override
            public void onProgress(int bytesSent, int totalBytesSent, int totalBytesToSend) {
                int percent = (totalBytesSent * 100) / totalBytesToSend;
                Log.i(TAG, "Sending..." + percent);
            }
            @Override
            public void onSent(FileMessage message, SendBirdException e) {
                if (e != null) {
                    Log.i(TAG, "If WiFi is interrupted, an error will be received here");
                    e.printStackTrace();
                } else {
                    Log.i(TAG, "File sent!");
                }
            }
        });
    }

    private void copyInputStreamToFile(InputStream in, File file) {
        OutputStream out = null;
        try {
            out = new FileOutputStream(file);
            byte[] buf = new byte[1024];
            int len;
            while((len=in.read(buf))>0){
                out.write(buf,0,len);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            try {
                if ( out != null ) {
                    out.close();
                }
                in.close();
            }
            catch ( IOException e ) {
                e.printStackTrace();
            }
        }
    }

All the required permissions are granted. File create and upload image code is working too. Sometimes I can upload images in the open channel with the same code but most of the time it is showing an error. Can you please check the logs I have attached above?

I have used the same code in the Group channel to upload an image and it is working perfectly.

Thanks!

No problem. Will check.

Question: This error happens even if you entered an Open Channel and then you want to send a file message?

yes, I entered an open channel and get all the messages from that channel. Now while sending an image, I am getting an error.

I tried reproducing this error but I can’t…

Starting version 3.0.153 you can set logging levels:

SendBird.setLoggerLevel(LogLevel.ERROR);

Can you please try upgrading and see if you can get more stack trace for this error?

Please find attached log file from below link.
https://drive.google.com/file/d/1jv1BuHqDX7wzibrHOe280u5ULcweO7Yl/view?usp=sharing

Thank you. Will check this.

After analysing this info, we can say that you need to make sure the following steps are followed:

  1. init
  2. connect
  3. get channel
  4. enter
  5. send message

It’s important to wait for the callback before sending messages. It’s not possible to try sending information while the connection is unstable.

I have checked all these steps and added logs into it and I am not getting any error in any of these.

Init- Success
Connect - Success
Get channel - success
Enter channel - success
Get all messages of the channel - Success
Send Message - Getting an error.

Hi @Hio_Developer,
Is this issue resolved?

I’ve checked the log and I can’t see the part where you enter a channel from the log, thus the error from sending a file message is logged as SendBirdException{code=900020, message=Not a member.}.

Good information thanks for sharing
vmware