AWS S3 Rest API with Android Retrofit V2 library, uploaded image is damaged

后端 未结 6 1569
生来不讨喜
生来不讨喜 2020-12-03 08:57

I\'m trying upload a Image from my Android APP to Amazon AWS S3 and I need use AWS Restful API.

I\'m using Retrofit 2

6条回答
  •  一向
    一向 (楼主)
    2020-12-03 09:34

    You can use retrofit 2 to upload the image/file

    @Multipart
    @POST("/api/attachment")
    Call addAttachment(@Part MultipartBody.Part imageFile);
    

    Now to make the call:

     RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody.Part imageFileBody = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
    

    Note : Make sure you are using retrofit2 as for some reason I was unable to upload image using retrofit1 library.

提交回复
热议问题