我正在尝试使用Retrofit2从相机或图库上传图像 它运行完美,直到enqueue()方法,但是此后它返回400错误的requeat并显示以下响应: 像这样:D / OkHttp:������JFIF����������������C��....
Api通话:
(, )
片段中的上传方法:
@Multipart
@POST("feed/")
Call<ResponseBody> postFeedItem(@Part("location") RequestBody location,
@Part MultipartBody.Part m_Url);
图库或摄影机的结果:
private void sharePost(){
File file = new File(globalPost);
RequestBody filePart = RequestBody.create(MediaType.parse("image/*"),file);
MultipartBody.Part body = MultipartBody.Part.createFormData("m_Url",file.getName(),filePart);
Timber.i(file.toString());
String loc = location.getText().toString();
RequestBody loc_req = RequestBody.create(MultipartBody.FORM,loc);
if(loc !=null && file != null){
Call<ResponseBody> call = ApiClient.getApiClient().create(UserClient.class).postFeedItem(loc_req,body);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(getContext(),response.code(),Toast.LENGTH_LONG).show();
Timber.i(String.valueOf(response.code()));
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Timber.e(t.getMessage()+"onFailure()");
}
});
}
}