Before i will start i see a lot of questions about this but nothing works for me maybe someone can explained or display it to me how can compress bitmap to MultiPart entity and than send it to the server correct using Retrofit
Asked
Active
Viewed 4,772 times
5
-
what did you try ? – Saveen Aug 30 '17 at 08:14
2 Answers
2
For those who come here for solution, here's mine.
First create a temporary file based on that bitmap
Convert Bitmap to file in Android (Stack Overflow)
Then get that file and add as multipart file
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part fileBody = MultipartBody.Part.createFormData("imageFile", file.getName(), requestFile);

Monster Brain
- 1,950
- 18
- 28
1
First you create a ResponseBody of the file and parse it as a MultipartBody.Part:
// build request containing file
RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", "your_bitmap_file.bmp", fileBody);
This filePart can then be passed to your Retrofit Service, which should look like this:
@Multipart
@POST("/")
Call<ResponseBody> upload(@Part MultipartBody.Part file);

Piwo
- 1,347
- 1
- 12
- 19