4

I have a project containing a JSP page. I want it to have a file uploading form which it should post to a API which will process it . I am uploading 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 remove enctype="multipart/form-data" it's working fine but as soon as I put it there and recompile and run the project this error shows up:

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

I also need to know the place where the file gets uploaded . Is there a default location where it gets uploaded or we need to specify it ?

When i do this

` 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 .

Evan Root
  • 279
  • 1
  • 5
  • 19

0 Answers0