Need help in POST multiple image file using retrofit?

前端 未结 2 1731
-上瘾入骨i
-上瘾入骨i 2020-12-05 08:33

How to add multiple images/files on a same parameter along with other textual data using retrofit?

Single image is uploading perfectly using following interf         


        
2条回答
  •  孤城傲影
    2020-12-05 09:07

    You can use the @MultiPart Post with @PartMap as parameter

    Map files = new HashMap();
    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 Files
        );
    
    }
    

提交回复
热议问题