1

I have seen fair amount of threads regarding bad request errors upon file upload, however unlike for others, I am sure that Spring is not at fault here, as I am able to upload file via curl without an issue: curl -X POST -v http://localhost:8080/rest/datasets/ -T test.xlsx

ExtJS uploader:

{
            xtype: 'filefield',
            fieldLabel: 'Select file',
            name: 'file',
            fieldName : 'file',
            listeners: {
                change: function(filefield, value, eOpts) {
            var form = filefield.up('form').getForm();
            form.submit({
                url: '/rest/datasets',
                headers : {
                    'Accept' : '*/*',
                    'Content-Type' : 'multipart/form-data'
                },
                waitMsg: 'Uploading'
                });
                }
            }
        }

Spring controller

@RestController
@RequestMapping("rest/datasets")
public class DatasetController {

    @RequestMapping(method = RequestMethod.POST)
    public String uploadFile(
        @RequestParam("file") MultipartFile file) {
        ...
    }
}

I am using ExtJS 6.0.1 and Spring Boot 1.3.3

Coderino Javarino
  • 2,819
  • 4
  • 21
  • 43

1 Answers1

3

I don't believe it's ExtJS at fault here. I checked your sample in sencha fiddle, and it seems that parameter "file" does exist when posting.

------WebKitFormBoundaryCL4R6o6o2MXXQcAx
Content-Disposition: form-data; name="file"; filename="Capture1.PNG"
Content-Type: image/png
------WebKitFormBoundaryCL4R6o6o2MXXQcAx--

You could also try: Spring mvc: HTTP Status 400 - Required MultipartFile parameter 'file' is not present

Community
  • 1
  • 1
Gašper
  • 815
  • 8
  • 14