2017-01-04 28 views
1

我正在研究android中的quickblox消息附件功能。quickbloxsdk:通过的对象不是文件,不正确的内容类型?

我想要做的是: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

我发现了这个解决方案。

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

要解决该问题,我只需下载新文件&我的代码与魅力工作。

+0

可以请您分享这些问题的示例代码。我必须从camara/gallery上传图片 – Pallavi

+0

@Pallavi你究竟想要什么? 我的意思是uploadFileTask only或文件选择来自gallary + uploadFileTask? – buzzingsilently

+0

我有gallary部分,但我想同步 – Pallavi

相关问题