我使用okhttp和retrofit2发布音频文件,但有时文件损坏(服务器端),是什么原因?
File file = new File(path);
RequestBody requestFile = RequestBody.create(MediaType.parse("audio/*"), file);
body = MultipartBody.Part.createFormData("audio_file", file.getName(), requestFile);
HashMap<String,RequestBody> params = new HashMap<>();
params.put("lecture_id",RequestBody.create(MediaType.parse("multipart/form-data"), mId + ""));
params.put("duration",RequestBody.create(MediaType.parse("multipart/form-data"),attachment.getDuration() + ""));
params.put("reply_message_id",RequestBody.create(MediaType.parse("multipart/form-data"),msg.getReplyMsgId() + ""));
Subscription subscription = ApiService.getInstance().sendAudioMessage(body,params).subscribe(new HttpObserver<IMMessage>() {
@Override
protected void onError(ApiException ex) {
CrashReport.postCatchedException(ex);
ToastUtil.showToast(getActivity(),ex.getMsg());
onSendMessageFail(msg);
}
@Override
public void onNext(IMMessage imMessage) {
onSendMessageSuccess(msg);
}
});
mCompositeSubscription.add(subscription);