android - Retrofit and Multipart Image Uploading with HTTP 400 -
im start crying, because ive tried many solutions , topics, doesn`t work.
the issue: have upload string (it bitmap, have base64 coded) our lovely server, have created background thread in android it, , calling backend. http 400 error message, following message:
org.springframework.web.bind.missingservletrequestparameterexception","message":"required multipartfile parameter 'file' 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 following part:
enctype: "multipart/form-data”). , don`t understand why, retforit interce looks this:
@post("/newimage") @multipart string uploadimagetoidea(@query("id") string id, @part("file") string file );
i don`t understand error message, because have file param here.
i had tried following (didn`t work obviously:
- retrofit multipart upload image failed
- retrofit - @body parameters cannot used form or multi-part encoding (added @headers, in case had more header before request, didn`t changed anything.)
my code call backend (not final version, first let things make work :) ):
new thread() { @override public void run() { multiparttypedoutput file = new multiparttypedoutput(); (int = 0; < 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 backend developer:
you need send multipart request (enctype="multipart/form-data”).
so, can please me out, why have http 400 error message above? can change in code make call work ? thank you
you should use typedfile sending file in multipart.
@multipart @post("/newimage") string uploadimagetoidea(@part("id") typedstring id, @part("file") typedfile file);
for more information link.
Comments
Post a Comment