The file upload function does not work || The directory where the file is saved after downloading

I have a project containing a JSP page. I want him to have a file upload form that she needs to submit to an API that will process it. I upload it through

<form action="api/processExcel" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" /> 
</form>

when I delete enctype="multipart/form-data", it works fine, but as soon as I put it there and recompiled and started the project, this error appears:

Invalid CSRF Token 'null' was found on the 
request parameter '_csrf' or header 'X-CSRF-TOKEN'.

I also need to know the file upload location. Is there a default place where it is loaded, or do we need to specify it?

When i do it

` try {
            http
             .csrf().disable();
//           .authorizeRequests()
//           .antMatchers("/static/**").permitAll()
//           .antMatchers("/settings/api/**").permitAll()
//           .antMatchers("/api/**").permitAll()
//           .anyRequest().authenticated()
//           .and()
//           .formLogin()
//           .loginPage("/login").permitAll()
//           .defaultSuccessUrl("/index",true)  ;    
    }`

and disable csrf, it starts working fine.

+4
source share

All Articles