• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Problem in spring with HTTP post request with a file and content = application/x-www-form-urlencoded

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a controller in Spring boot which looks this :

public ResponseEntity<String> install(@RequestBody byte[] body,
@RequestParam(name = "param1", required = false) String param1,
@RequestParam(name = "param2", required = false) String param2)

where body is a file (xml, txt, zip ...).

This works fine when the Header content is "text/plain", I can get back the posted file and the params.

But my controller will be called with a header content = application/x-www-form-urlencoded, the caller is out of my scope, so I dont have choice, my code must be able to get back a file post with application/x-www-form-urlencoded.

Until now, I cannot make my code working with this header as soon as a file is posted. I don't understand how the file is posted with x-www-form-urlencoded and how I can get back the file with Spring.

I tried to not use @RequestBody any more and to use instead :
- @RequestParam MultiValueMap body
- @RequestParam Map<String, String> body
It does'nt work  : it looks the original file is cut in many fragments.

Finally I wonder is there's a way in Spring  to get back a file posted with application/x-www-form-urlencoded ?

Thanks for your help.
Anna.
 
Saloon Keeper
Posts: 14665
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Take a look at the consumes field of the @RequestMapping annotation.
reply
    Bookmark Topic Watch Topic
  • New Topic