danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.6k forks source link

Upload.upload only send .gif files as multipart #1968

Open sagivStekolshik opened 7 years ago

sagivStekolshik commented 7 years ago

I use a java spring back end this is the server:

@Controller
public class FileController {
    @Bean
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver=new CommonsMultipartResolver();
        resolver.setDefaultEncoding("utf-8");
        return resolver;
    }

    @ResponseStatus(HttpStatus.OK)
    @RequestMapping(value = "/upload")
    public void upload(@RequestParam("file") MultipartFile file ) throws IOException {
        if (!file.isEmpty()) {
            System.out.println(String.format("receive %s", file.getName()));
        }
    }
}

for some resone i get 400 Bad Request headers when i try to send an image thats not a .gif file. for a gif it works fine. my service that upload is

Upload.upload({
            url: '/upload',
            data: {
                file: file
            }
        }).then(function (resp) {
                console.log("file uploaded",resp)
            }, function (err) {
                console.log("somthing went wrong",err)
            }, function (evt) {
            console.log("uploading",evt)
        })

hope someone can shed some light on this mystery

Kaijiro commented 6 years ago

Did you try without your CommonsMultipartResolver Bean ? I'm using the default one and it is fine for me.