改造2 RequestBody writeTo()方法两次,我使用的代码如下:
ProgressRequestBody requestVideoFile = new ProgressRequestBody(videoFile, new ProgressRequestBody.UploadCallbacks() {
VideoUploadStore store = new VideoUploadStore();
@Override
public void onProgressUpdate(int percentage) {
if (!mIsCancelled) {
Log.i("UploadServiceManager", "Read Percentage : " + percentage);
data.setUploadPercentage(percentage);
store.updateUploadData(data);
}
}
@Override
public void onError() {
if(!mIsCancelled) {
data.setUploadPercentage(0);
store.updateUploadData(data);
}
}
@Override
public void onFinish() {
}
});
MultipartBody.Part multipartVideo = MultipartBody.Part.createFormData("File", videoFile.getName(), requestVideoFile);
最佳答案
以下解决方案可能会为您提供帮助,尽管可能为时已晚。 :p
删除Api客户端中的HttpLoggingInterceptor
对象,该对象将不会执行两次writeTo()函数。基本上,HttpLoggingInterceptor
首先通过调用writeTo()加载数据缓冲区(出于内部日志记录目的),然后再次调用writeTo()将数据上传到服务器。
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
httpClient.addInterceptor(logging);
关于java - 改造2 RequestBody writeTo()方法被调用两次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40691610/