java - quickbloxsdk : Passed object is not file, 内容类型不正确?

标签 java android android-intent quickblox

我正在研究 android 中的 quickblox 消息附件功能。

我想做的是:OnViewClicked 一个 CreateChooser(type:images/*) 将打开。 选择图像后,它将进入存储 UrionActivityResult 方法。 发布正在调用 sendAttachment 函数。

这是我的编码部分:

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 错误:

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

最佳答案

我找到了解决方案。

每当您尝试添加设备上实际不存在的文件时,就会出现此类错误。

为了解决这个问题,我只是下载了新文件,我的代码非常有效。

关于java - quickbloxsdk : Passed object is not file, 内容类型不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41463709/

相关文章:

java - jconnect 支持 ASE 15.0.3

java - JPannel 组件之间的通信

javascript - 如何通过@react-native-community/slider 在android中创建垂直 slider ?

android - 如何将 putExtra() 和 getExtra() 用于字符串数据

android - 使用最大数量的共享首选项

java - 警报 JSP 后保持输入的详细信息不变

java - JBOSS 5_1_0 GA 是否支持在 WAR 中打包 EJB?

java - 从 Imageview 中的图像中获取特定颜色的所有像素

android - Facebook 登录回调多次触发

java - Android - 语音识别而不是语音