title: Tomcat Performance with Spring Boot API for File Upload
body: <p>I have a Spring boot API and one of the endpoints allows users to upload video's. Now My controller basically takes the file as a MultiPart file and then I store it in a temp folder accessible to tomcat. Once I have it stored on Disk, I then push the video to an S3 bucket.</p>
  <p>Now to me anyway, this seems to be less than optimal, Like if I wanted to have a 100 or a 1000 users upload at once it seems really non performant to write the files to disk first.</p>
  <p>As a little background I'm storing it on disk with the intention that if there is a issue pushing to S3 I can retry</p>
  <p>The below code might show what I'm doing better than the above:</p>
  <pre><code>public Video addVideo(@RequestParam(&quot;title&quot;) String title,
      @RequestParam(&quot;Description&quot;) String Description,
      @RequestParam(value = &quot;file&quot;, required = true) MultipartFile file) {         
             this.amazonS3ClientService.uploadFileToS3Bucket(file, title, description));
  }
  </code></pre>
  <p>Method for storing Video file:</p>
  <pre><code>String fileNameWithExtenstion = awsS3FileName + &quot;.&quot; + FilenameUtils.getExtension(multipartFile.getOriginalFilename());
  
  //creating the file in the server (temporarily)
  File file = new File(tomcatTempDir + fileNameWithExtenstion);FileOutputStream fos = new FileOutputStream(file);
  
  fos.write(multipartFile.getBytes());
  
  fos.close();PutObjectRequest putObjectRequest = new PutObjectRequest(this.awsS3Bucket, awsS3BucketFolder + UnigueId + &quot;/&quot; + fileNameWithExtenstion, file);
  
  if (enablePublicReadAccess) {
      putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead);
  }
  
  // Upload a file as a new object with ContentType and title 
  
  specified.amazonS3.putObject(putObjectRequest);
  //removing the file created in the server
  file.delete();
  </code></pre>
  <p>So my question is....is there a better way in Tomcat to:</p>
  <p>A) Take in a file via a controllerB) Push to S3</p>