Skip to content

Uploading mp4 from Android phone to Spring server results in file missing a few hundred bytes if bigger than 2MB

I have been trying to upload to a Java Spring server running on my laptop, using an app written in Xamarin forms, using a physical Redmi Android device.

But when I send out the multi-part request, if it is bigger than about 2MB, the file loses a few hundred bytes by the time it reaches the server.

For example, the original video file has 8,268,891 bytes. Sometimes the file that reaches the server will have 8,267,175 and sometimes 8,269,279 or some other random number.

I don’t know if it’s related to my Xamarin code, because this seems to happen whether I use multi-part requests or send it as a base64 string in a request.

But just in case, here is my multi-part Xamarin code

               var multipartContent = new MultipartFormDataContent();
                var videoBytes = new ByteArrayContent(file.GetStream().ToByteArray());
                multipartContent.Add(videoBytes, "file", file.Path.FileName());
                multipartContent.Add(new StringContent(serializedRequest, Encoding.UTF8, "application/json"), "request");

                content = multipartContent;

            switch (type)
                case RequestType.Post:
                    result = await client.PostAsync(_siteUrl + apiPath, content, cancellationToken);

And my controller on the Spring server

  @RequestMapping(value = { RequestMappingConstants.MOBILE + RequestMappingConstants.UPLOAD + RequestMappingConstants.UPLOAD_VIDEO }, method = RequestMethod.POST)
  public @ResponseBody VideoUploadResponse uploadVideo(@RequestPart(value="request") VideoUploadRequest request, @RequestPart(value="file") MultipartFile file, HttpServletRequest httpRequest) {"Inside video upload");
      return uploadService.uploadWelcomeVideo(request, file, httpRequest);


Also, my settings on the server:

multipart.maxFileSize= 100MB
multipart.maxRequestSize= 100MB

Again, this happens as long as the video file exceeds about 2MB. The corrupted file that reaches the server is unplayable. The server and client are running on the same wi-fi network.

I would be very grateful if you could help.


It turned out to be something wrong with my laptop or wireless network that was causing packet loss. Nothing to do with the code, as it was working when I tried it on a production server