【发布时间】:2018-11-07 16:03:23
【问题描述】:
在我的应用程序中,我希望使用Retrofit2 将图像从手机上传 到服务器。
对于这项工作,我从互联网上找到了一些来源,但在一个来源中使用这个:
public interface RetrofitInterface {
@Multipart
@POST("/images/upload")
Call<Response> uploadImage(@Part MultipartBody.Part image);
}
在下面的其他来源中:
public interface ApiConfig {
@Multipart
@POST("images/upload_image.php")
Call<ServerResponse> upload(
@PartMap Map<String, RequestBody> map);
}
在第一个来源中使用@Part MultipartBody.Part image,在第二个来源中使用@PartMap Map<String, RequestBody> map。
两者有什么区别?
我用哪个更好?
【问题讨论】:
-
@Gokulraj,谢谢亲爱的。但我的问题是上述代码有什么区别?
-
PartMap 不支持多个同名部件
-
@AD10,谢谢。我只想发送图片。
标签: java android retrofit2 image-uploading