java quickbloxsdk:传递的对象不是文件,内容类型不正确?
我正在安卓上开发quickblox消息附件功能
我想做的就是:OnViewClicked
一个CreateChooser(type:images/*)
将是开放的。
选择图像后,它将进入onActivityResult
方法,在该方法中存储Uri
。
发布正在调用的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
# 1 楼答案
试试下面的代码。我可以上传图像、视频和音频
# 2 楼答案
我找到了解决办法
每当您试图添加设备上物理上不存在的文件时,就会显示此类错误
为了解决这个问题,我下载了新文件&;我的代码很有魅力
# 3 楼答案
与其使用
uri.getPath()
获取文件,不如使用uri.getLastPathSegment()