Search code examples
javaandroidandroid-intentquickblox

quickbloxsdk : Passed object is not file,Incorrect content type?


I am working on quickblox message attachment functionality in android.

What all I am trying to do is : OnViewClicked one CreateChooser(type:images/*) would be open. After selecting an image it will come to onActivityResult method where it stores Uri. Post that sendAttachment function is being called.

Here is my coding portion :

private Uri uri;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case FILE_SELECT_CODE:
            if (resultCode == RESULT_OK) {
                // Get the Uri of the selected file
                uri = data.getData();
            }
            break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

public void sendAttachment() {

        File filePhoto = new File(uri.getPath());
        Boolean fileIsPublic = false;

        QBContent.uploadFileTask(filePhoto, fileIsPublic, null, new QBProgressCallback() {
            @Override
            public void onProgressUpdate(int i) {
                // i - progress in percentages
                Log.e(TAG, "onProgressUpdate: " + i);
            }
        }).performAsync(new QBEntityCallback<QBFile>() {
            @Override
            public void onSuccess(QBFile qbFile, Bundle bundle) {

                Integer id = qbFile.getId();

                // create a message
                QBChatMessage chatMessage = new QBChatMessage();
                chatMessage.setProperty("save_to_history", "1"); // Save a message to history

                // attach a photo
                QBAttachment attachment = new QBAttachment("photo");
                attachment.setId(qbFile.getId().toString());
                chatMessage.setBody("");
                chatMessage.addAttachment(attachment);

                // send a message
                try {
                    mQBChatDialog.sendMessage(chatMessage);
                    mtvEmpty.setVisibility(View.INVISIBLE);
                } catch (SmackException.NotConnectedException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(QBResponseException errors) {
                Log.e("DATA", TextUtils.join(",", errors.getErrors()));
            }
        });
}

LOGCAT ERROR :

E/ERROR: File upload onError,File does not exist,Passed object is not file,Incorrect content type


Solution

  • I found out a solution on this.

    This type of error displays whenever you try to add file that does not exist on your device physically.

    To resolve the problem I simply downloaded new file & my code worked with a charm.