• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Joe Ess
  • salvin francis

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

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
Saloon Keeper
Posts: 10981
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Take a look at the consumes field of the @RequestMapping annotation.
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!