【发布时间】:2017-01-17 20:42:17
【问题描述】:
我正在尝试使用 Retrofit2 将图像上传到服务器,但我非常不确定如何执行此操作。
文档让我有些困惑,我尝试了here 中提到的解决方案,但它对我不起作用。
这是我目前正在使用的代码 sn-p,它不会向服务器发送任何内容:
// Service
@Multipart
@POST("0.1/gallery/{galleryId}/addImage/")
Call<ResponseBody> addImage(@Path("galleryId") String galleryId, @Part MultipartBody.Part image);
//Call
MultipartBody.Part imagePart = MultipartBody.Part.createFormData("image", file.getName(), RequestBody.create(MediaType.parse("image/*"), file));
Call<ResponseBody> call = service. addImage("1234567890", imagePart);
但是,我可以使用带有 TypedFile 的 Retrofit 1.9 来做到这一点。
是我做错了什么还是 Retrofit2 对这类事情有问题?
【问题讨论】:
-
尝试使用
"multipart/form-data"而不是"image/*" -
你终于做到了吗?如果没有,请告诉我