Android Retrofit Base64 @Body

我怕爱的太早我们不能终老 提交于 2019-11-29 07:56:00

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, "...", "...");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!