Android Retrofit Base64 @Body

前端 未结 1 1276
余生分开走
余生分开走 2020-12-18 08:46

Hi all i have this code in android 4.3 and i am using retrofit just now but server thrown me an error message \"The input is not a valid Base-64 string as it contains a non

相关标签:
1条回答
  • 2020-12-18 09:21

    For general object types (String included) Retrofit is going to use its Converter to serialize the value. In this case, Gson is used by default to serialize the body as JSON.

    In order to upload Base64-encoded data you want to use TypedInput. This tells Retrofit that you will pass it the raw body which is already serialized and an associated Content-Type value.

    @PUT("/PhotoService/{PROPERTYID}/{WATERMARK}")
    String uploadPhoto(
        @Body TypedInput photo,
        @Path("PROPERTYID") String propertyId,
        @Path("WATERMARK") String watermark);
    

    I'm going to assume that b is a byte[] in your above example. Here I'm using an existing implementation of TypedInput: TypedByteArray

    TypedInput body = new TypedByteArray("application/x-www-form-urlencoded", b);
    service.uploadPhoto(body, "...", "...");
    
    0 讨论(0)
提交回复
热议问题