Im about to start crying, because Ive tried many solutions and topics, but it doesn`t work.
The issue: I have to upload an String (it was a bitmap, but I have base64 coded) to our lovely server, so I have created a background Thread in Android to do it, and calling the backend. I get a HTTP 400 error message, with the following message:
org.springframework.web.bind.MissingServletRequestParameterException","message":"Required MultipartFile parameter 'file' is not present","path":"/backend/newimage"}.
My headers:
Content-Disposition: form-data; name="file"
Content-Type: text/plain; charset=UTF-8
Content-Length: 24069
Content-Transfer-Encoding: binary
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsK.......etc.....binary
I don`t see in headers the following part:
enctype: "multipart/form-data”). and I don`t understand why, my retforit interce looks like this:
@POST("/newimage")
@Multipart
String uploadImageToIdea(@Query("id") String id, @Part("file") String file );
I don`t understand the error message, because I HAVE the file param here.
I had tried the following (didn`t work obviously:
- Retrofit Multipart Upload Image failed
- Retrofit - @Body parameters cannot be used with form or multi-part encoding (added @Headers, in this case I had more header before my request, but didn`t changed anything.)
my code to call the backend (not the final version, but first let things make work :) ):
new Thread() {
@Override
public void run() {
MultipartTypedOutput file = new MultipartTypedOutput();
for (int i = 0; i < imagesToUpload.size(); ++i) {
Bitmap imageBitmap = imagesToUpload.get(i);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream);
byte[] byteArray = stream.toByteArray();
String bitmapString = Base64.encodeToString(byteArray, Base64.DEFAULT);
backend.uploadImageToIdea(submitIdeaResponse.getIdeaDetails().getId(), bitmapString);
}
}
}.start();
Note from my backend developer:
You need to send a multipart request (enctype="multipart/form-data”).
So, can someone please help me out, why I have HTTP 400 with the error message above? What can I change in my code to make this call work ? Thank you