I am trying to upload the image using retrofit in Base64 format.
To convert bitmap to Base64,
public static String convertImageToStringForServer(Bitmap imageBitmap){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
if(imageBitmap != null) {
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream);
byte[] byteArray = stream.toByteArray();
return Base64.encodeToString(byteArray, Base64.DEFAULT);
}else{
return null;
}
}
I do not want to upload the image using Typedfile.
My request method is below,
@Multipart
@POST("/pingpong")
void doPingpong(@Part ("access_token") TypedString accessToken,
@Part("image") TypedString profileImage,
@Part("pixels") TypedString doPingPong,Callback<pixelsPing> callback);
Base64 conversion is correct, but I am not getting the image on server. What am i doing wrong in the above?
Post your Base64 string as a Field parameter of your request. Also use the FormUrlEncoded annotation, which adds "application/x-www-form-urlencoded" content type.
@POST("/upload")
@FormUrlEncoded
void upload(@Field("image") String base64, Callback<ResponseObject> callback);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With