android - 在使用改造发布多个图像文件方面需要帮助吗?

标签 android retrofit

如何使用改造在同一参数上添加多个图像/文件以及其他文本数据?

Single image is uploading perfectly using following interface
    @Multipart
    @POST("/users/updateProfile/")
    public void updateProfileWithImage(
                    @Part("user_id") TypedString first_name,
                    @Part ("image") TypedFile image, 
                    Callback<WebResponse> callback);

最佳答案

您可以使用带有@PartMap 作为参数的@MultiPart Post

Map<String, TypedFile> files = new HashMap<String, TypedFile>();
files.put("my file number one", new TypedFile("image/jpg", new File(filename)));
files.put("my file number two", new TypedFile("image/jpg", new File(filename)));

apiInterface.updateProfileWithImage("first name here", files);

private interface ApiInterface{
    @Multipart
    @POST("/users/updateProfile/")
    Response updateProfileWithImage(
     @Part("user_id") TypedString first_name,
     @PartMap Map<String,TypedFile> Files
    );

}

关于android - 在使用改造发布多个图像文件方面需要帮助吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22658797/

相关文章:

android - EditText 的提示被切断,因为我的提示文本超过一行。 editText 只显示一行。我怎样才能使整个提示可见?

键盘启动时Android ScrollView不滚动

android - 如何防止 Retrofit 自动跟随 302

android - 从我的应用程序接听来电

安卓 : Cdata in xml not parsing correctly(sax)

Android 和 libCurl https

Android studio 1.1.0 设置 minifyEnabled true 导致应用程序出现问题

android - java.io.IOException : stream was reset: REFUSED_STREAM on several devices

java - RxJava onErrorResumeNext()

Android OkHttp,刷新过期 token