title: Spring Boot Multipart File Upload Size Inconsistency
body: <p>I have an endpoint that uploads an image file to the server, then to S3. </p>
  
  <p>When I run on localhost, the MultipartFile byte size is correct, and the upload is successful.</p>
  
  <p>However, the moment I deploy it to my EC2 instance the uploaded file size is incorrect. </p>
  
  <p>Controller Code</p>
  
  <pre><code>@PostMapping("/{id}/photos")
  fun addPhotos(@PathVariable("id") id: Long,
                @RequestParam("file") file: MultipartFile,
                jwt: AuthenticationJsonWebToken) = ApiResponse.success(propertyBLL.addPhotos(id, file, jwt))
  </code></pre>
  
  <p>Within the <code>PropertyBLL.addPhotos</code> method, printing file.size results in the wrong size.</p>
  
  <p>Actual file size is 649305 bytes, however when uploaded to my prod server it reads as 1189763 bytes.</p>
  
  <ul>
  <li>My production server is an AWS EC2 instance, behind Https. </li>
  <li>The Spring application yml files are the same. The only configurations I overrode were the file max size properties.</li>
  <li>I'm using PostMan to Post the request. I'm passing the body as form-data, key named "file". </li>
  <li>Again, it works perfectly when running locally.</li>
  </ul>
  
  <p>I did another test where I wrote the uploaded file to the server so I could compare.</p>
  
  <p>Uploaded file's first n bytes in Hex editor:</p>
  
  <p><code>EFBFBD50 4E470D0A 1A0A0000 000D4948 44520000 03000000 02400802 000000EF BFBDCC96 01000000 0467414D 410000EF BFBDEFBF BD0BEFBF BD610500 00002063 48524D00 007A2600</code></p>
  
  <p>Original file's first n bytes:</p>
  
  <p><code>89504E47 0D0A1A0A 0000000D 49484452 00000300 00000240 08020000 00B5CC96 01000000 0467414D 410000B1 8F0BFC61 05000000 20634852 4D00007A 26000080 840000FA 00000080</code></p>
  
  <p>They both appear to have the text "PNG" in them and also have the ending EXtdate:modify/create markers. </p>
  
  <p>Per Request, the core contents of addPhoto:</p>
  
  <pre><code>val metadata = ObjectMetadata()
  metadata.contentLength = file.size
  metadata.contentType = "image/png"
  LOGGER.info("Uploading image of size {} bytes, name: {}", file.size, file.originalFilename)
  val request = PutObjectRequest(awsProperties.cdnS3Bucket, imageName, file.inputStream, metadata)
  awsSdk.putObject(request)
  </code></pre>
  
  <p>This works when I run web server locally. imageName is just a custom built name. There is other code involving hibernate models, but is not relevant. </p>
  
  <p><strong>Update</strong></p>
  
  <p>This appears to be Https/api proxy related. When I hit the EC2 node's http url, it works fine. However, when I go through the api proxy (<a href="https://api.thedomain.com" rel="nofollow noreferrer">https://api.thedomain.com</a>), which proxies to the EC2 node, it fails. I will continue down this path.</p>