What is the best way to send a file using the RestService? I have an image that I have to send to the server.
The API expects the following POST data:
image -> image I want to send
description -> text
title -> text
Can I just send an object with the needed values to achieve this or do I have to do it another way?
class NewImage {
private Bitmap image;
private String description;
private String title;
}
You should use a multipart POST request:
Client:
Usage:
I know this has some boilerplate, but it will be improved in the near future.
Reflect for the question in the comment:
You can create a class:
Then use it as a converter. This will convert your objects to text/plain parts. However, maybe it is better to serialize this complex structure into JSON instead of sending it in the multipart post.