Geting HTTP Status 400 - Required MultipartFile parameter 'file' is not present in spring

后端 未结 3 382
小蘑菇
小蘑菇 2021-01-12 14:14

I am trying to upload a file using spring. Below is my code how I am working on it but if I try to use it I am getting this response:

HTTP

相关标签:
3条回答
  • 2021-01-12 14:38

    it works for me after i wrote in that input box name of the parameter "file" when i already have well configured the bean id in the Krajee bootstrap inputfile example ("https://github.com/kartik-v/bootstrap-fileinput").

    0 讨论(0)
  • 2021-01-12 14:41

    Spring needs the

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

    bean to handle file-uploads.

    You should register this bean in your application context file.

    The Content-Type should also be valid. In your case enctype="multipart/form-data"

    EDIT1:

    You can give the upload and memory size to the bean properties:

      <bean id="multipartResolver"
            class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <!-- max upload size in bytes -->
            <property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
    
            <!-- max size of file in memory (in bytes) -->
            <property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
    
        </bean>
    
    0 讨论(0)
  • 2021-01-12 14:44

    when you select the file in advance rest client, on the right side there is a input box, write in that input box name of the parameter, in your case name of parameter is file

    Parameter name defined here in controller @RequestParam("file")

    0 讨论(0)
提交回复
热议问题