0

I am trying to create an upload tool with Spring-MVC. And I am getting HTTP 400. What am I dong wrong? (eventually front end guy will be uploading a file using angularjs)

My Controller:

@Controller
public class UploadController {

@Autowired public DBInsertService service;

@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = "multipart/form-data")
public @ResponseBody
String upload(@RequestParam("file") MultipartFile file, HttpServletResponse httpResponse) {
    System.out.println("He hit me");

    return service.insertData(file);            
}

HTTP Request in Fiddler:

enter image description here

Hoàng Long
  • 10,746
  • 20
  • 75
  • 124
gumenimeda
  • 815
  • 7
  • 15
  • 43
  • I don't see much problem in your java code. Does it work with a simple HTML file submit form? – Hoàng Long Jun 08 '15 at 13:53
  • @HoàngLong I didn't test with HTML, I usually test my services with Fiddler. I thought that someone whould recognize what is wrong by looking at request headers. Maybe the boundary should somehow be defined on the server... – gumenimeda Jun 08 '15 at 13:57
  • Uhm.. maybe there's someone who's willing to remember those details. I think you can test it with the simple HTML form to eliminate the case that the request is malformed – Hoàng Long Jun 08 '15 at 14:16
  • FYI, you can check the structure of a file upload request here: http://stackoverflow.com/questions/14962592/whats-content-type-value-within-a-http-request-when-uploading-content . It isn't quite match with your posted request. But of course, I'm not sure the part you post is all the request. – Hoàng Long Jun 08 '15 at 14:20
  • How are you testing other controllers (that are not file upload)? – acdcjunior Jun 08 '15 at 14:22
  • I use another tool HTTP Live Header (firefox plugin). However, the tool is irrelevant here. What I'm suggesting is that we can try to eliminate the possible cause of your problem, by utilizing the error-proof file upload client of the browser. – Hoàng Long Jun 08 '15 at 14:44

0 Answers0