简体   繁体   English

从 Android 手机上传 mp4 到 Spring 服务器导致文件丢失几百字节如果大于 2MB

[英]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.我一直在尝试上传到在我的笔记本电脑上运行的 Java Spring 服务器,使用 Xamarin.forms 编写的应用程序,使用物理 Redmi Android 设备。

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.但是当我发出多部分请求时,如果它大于大约 2MB,文件到达服务器时会丢失几百个字节。

For example, the original video file has 8,268,891 bytes.例如,原始视频文件有 8,268,891 字节。 Sometimes the file that reaches the server will have 8,267,175 and sometimes 8,269,279 or some other random number.有时到达服务器的文件有 8,267,175,有时有 8,269,279 或其他一些随机数。

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.我不知道它是否与我的 Xamarin 代码有关,因为无论我使用多部分请求还是在请求中将其作为 base64 字符串发送,这似乎都会发生。

But just in case, here is my multi-part Xamarin code但以防万一,这是我的多部分 Xamarin 代码

               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);
                    break;

And my controller on the Spring server而我的 controller 在 Spring 服务器上

  @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) {
      LOG.info("Inside video upload");
      return uploadService.uploadWelcomeVideo(request, file, httpRequest);

} }

Also, my settings on the server:另外,我在服务器上的设置:

multipart.maxFileSize= 100MB
multipart.maxRequestSize= 100MB
spring.servlet.multipart.enabled=true 
spring.servlet.multipart.file-size-threshold=2KB 
spring.servlet.multipart.max-file-size=200MB 
spring.servlet.multipart.max-request-size=215MB 
spring.servlet.multipart.resolve-lazily=false 

Again, this happens as long as the video file exceeds about 2MB.同样,只要视频文件超过 2MB,就会发生这种情况。 The corrupted file that reaches the server is unplayable.到达服务器的损坏文件无法播放。 The server and client are running on the same wi-fi.network.服务器和客户端在同一个 wi-fi.network 上运行。

I would be very grateful if you could help.如果您能提供帮助,我将不胜感激。

I have found that you also need to adjust the Tomcat and/or Jetty (as appropriate) settings:我发现您还需要调整 Tomcat 和/或 Jetty(视情况而定)设置:

server.jetty.max-http-form-post-size: 100MB                                      
                                                                                
server.tomcat.max-http-form-post-size: 100MB                                     
server.tomcat.max-swallow-size: -1

It turned out to be something wrong with my laptop or wireless.network that was causing packet loss.原来是我的笔记本电脑或 wireless.network 出了问题,导致丢包。 Nothing to do with the code, as it was working when I tried it on a production server与代码无关,因为当我在生产服务器上尝试它时它正在工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Android手机上传文件到FTP服务器? - Uploading a file to a FTP server from android phone? 如何将Raw文件夹中的mp3 / mp4文件发送到Android上的服务器? - How to send the mp3/mp4 file from Raw folder to server on Android? Android JAVA $ _FILE会在大于约50 mb的文件中清空内容 - Android JAVA $_FILE returms empty at files bigger than ~ 50 mb 从服务器流式传输文件时,磁盘上的文件大小大于读取的总字节数,这是怎么回事? - When streaming a file from a server, the file size on disk is bigger than the total bytes read, what's going on? Android Volley无法处理2mb json文件 - Android volley can't handle a 2mb json file android将视频文件(mp4)发送到php服务器 - android send video file (mp4) to php server 在Android中从服务器播放mp4视频时出错 - Error while playing the mp4 videos from server in Android 我想从服务器下载文件,并在Android中使用各种文件扩展名(例如(pdf,doc,mp4,jpeg))查看文件 - I want to download the file from server and view the file in android with various file Extensions like (pdf,doc,mp4,jpeg)) 无法从解析服务器下载大于 20mb 的 pdf 文件 - Unable to download pdf files bigger than 20mb from parse server Android活动每次增加2mb - Android activity adds 2mb every time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM