[英]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.