post - RestTemplate upload image as MultipartFile with Content-Type image/jpg -
i trying upload image (multipartfile) using resttemplate server url. sending request postman works content-type: image/jpg
, image sent binary file body.
method implementation in springboot:
public responseentity<string> uploadimage(multipartfile file) { resttemplate.getmessageconverters().add(new bytearrayhttpmessageconverter()); resttemplate.getmessageconverters().add(new bufferedimagehttpmessageconverter()); linkedmultivaluemap<string,object> params = new linkedmultivaluemap<>(); params.add("file", new filesystemresource(file)); httpheaders httpheaders = new httpheaders(); httpheaders.setcontenttype(mediatype.image_jpeg); httpentity<linkedmultivaluemap<string, object>> requestentity = new httpentity<>(params, httpheaders); return resttemplate.exchange(upload_url, httpmethod.post, requestentity, string.class);
exception:
org.springframework.web.client.restclientexception: not write request: no suitable httpmessageconverter found request type [org.springframework.util.linkedmultivaluemap] , content type [image/jpeg]
upload works content-type mediatype.multipart_form_data
rest service use accepts image/jpg
http content-type.
thanks.
Comments
Post a Comment