SoFunction
Updated on 2025-03-08

Java receives sample code for uploading ios files

This article shares with you the specific code of how Java receives ios file upload for your reference. The specific content is as follows

ios Multipart/form-data POST request java background spring interface keeps error. After two days of work, it finally solved it and accumulated

package ;

import ;
import ;
import ;
import ;
import ;
import ;

import ;
import ;

import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;

import ;

@Controller
@RequestMapping("/controller")
public class File1Controller {

 LinkedList<FileMeta> files = new LinkedList<FileMeta>();
 FileMeta fileMeta = null;

 /***************************************************
  * URL: /rest/controller/upload upload(): receives files
  * 
  * @param request
  *   : MultipartHttpServletRequest auto passed
  * @param response
  *   : HttpServletResponse auto passed
  * @return LinkedList<FileMeta> as json format
  * @throws IOException
  * @throws FileUploadException
  ****************************************************/
 @RequestMapping(value = "/upload", method = )
 @ResponseBody
 public String upload(HttpServletRequest request, HttpServletResponse response)
   throws IOException, FileUploadException {

  boolean isMultipart = (request);// Determine whether it is the form file type  DiskFileItemFactory factory = new DiskFileItemFactory();
  ServletFileUpload sfu = new ServletFileUpload(factory);
  List items = (request);// Get a list of all uploaded domains from request  for (Iterator iter = (); ();) {
   FileItem fileitem = (FileItem) ();
   if (!() && fileitem != null) {// The interpretation is not an ordinary form field or a file                // Operation file item file steps to get the size and path
    // Define the image output path    String imgPath = "e:" + () + ".jpg";
    // Define image stream    InputStream fin = ();

    // Define the image output stream    FileOutputStream fout = new FileOutputStream(imgPath);
    // Write a file    byte[] b = new byte[1024];
    int length = 0;
    while ((length = (b)) > 0) {

     (b, 0, length);
    }

    // Close the data flow    ();
    ();
   }

  }

  return "200";
 }

}

Add to

<!-- This is used for uploading files -->
  <dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.3.1</version>
  </dependency>
  <dependency>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
   <version>2.4</version>
  </dependency>

Add bean

<!-- Configuration file upload,If you do not use file upload, you can do not need to configure it,Of course if not worthy,Then the configuration file There is no need to introduce upload component packages in it -->
 <bean 
  class="">
  <!-- Default encoding -->
  <property name="defaultEncoding" value="utf-8" />
  <!-- Maximum file size -->
  <property name="maxUploadSize" value="10485760000" />
  <!-- Maximum value in memory -->
  <property name="maxInMemorySize" value="40960" />
 </bean>

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.