Spring MVC's MultipartFile to File read

The first method:

     MultipartFile file = xxx;
        CommonsMultipartFile cf= (CommonsMultipartFile)file;
        DiskFileItem fi = (DiskFileItem)cf.getFileItem();

        File f = fi.getStoreLocation();

  will be in the temporary folder of the project's root directory Generate a file; the

second method:

    transferTo(File dest);

  a new file will be generated in the project; the

third method:  

  File f = (File) xxx Just force the transfer. The premise is to configure multipartResolver, otherwise an exception of type conversion failure will be reported.

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="104857600"/>
        <property name="maxInMemorySize" value="4096"/ >
    </bean>


  Workbook wb = Workbook.getWorkbook(xxx .getInputStream());
  Convert to input stream and read directly;
The fifth method:
  byte[] buffer = myfile.getBytes();
  Convert to byte array first, haven't tried it;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326675741&siteId=291194637