上载图像时改造响应二进制文件

时间:2018-09-16 11:36:49

标签: android android-camera retrofit retrofit2 android-gallery

我正在尝试使用Retrofit2从相机或图库上传图像 它运行完美,直到enqueue()方法,但是此后它返回400错误的requeat并显示以下响应:  像这样:D / OkHttp:������JFIF����������������C��....

This is my server side request and response type information

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()");
            }
        });
    }
}

0 个答案:

没有答案