• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

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
  • 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: 10875
235
  • 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.
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!