简体   繁体   English

使用多部分/表单数据将文件上传到服务器

[英]Uploading file to server with multipart/form-data

I have this code: 我有以下代码:

Request restletRequest = getRequest();
HttpServletRequest servletRequest = ServletUtils.getRequest(restletRequest);
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator fileIterator = upload.getItemIterator(servletRequest);
LOG.info("File Item iterator - " + fileIterator.hasNext());
while (fileIterator.hasNext()) {
  // never reached
}

With log: 带日志:

[main] INFO com.xyzbackend.ServerResource - Media type - multipart/form-data; boundary=----WebKitFormBoundary5XV92DI2vfB2Z6NO
[main] INFO com.xyzbackend.ServerResource - Media size - 27671
[main] INFO com.xyzbackend.ServerResource - File Item iterator - false

The problem here is that it works on my local machine, meaning the "never reached" section is actually reached and the code executes fine. 这里的问题是,它可以在我的本地计算机上运行,​​这意味着“从未到达”部分实际上已经到达并且代码可以正常执行。 My problem is that when it gets uploaded to the cloud server (Linode with NGINX Unit server running) it starts behaving differently. 我的问题是,当它上传到云服务器(运行NGINX Unit服务器的Linode)时,它的行为开始有所不同。 The fileIterator.hasNext() is evaluated false. fileIterator.hasNext()的评估结果为false。

Based on experience, what could be the possible causes of such weird behavior? 根据经验,这种奇怪行为的可能原因是什么?

Currently, multipart feature is not supported by Java module in NGINX Unit. 当前,NGINX单元中的Java模块不支持multipart功能。 I would recommend you to create issue on GitHub to discuss and implement this one. 我建议您在GitHub上创建问题以讨论和实施这一问题。

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

相关问题 使用multipart / form-data android上传文件时出错 - Error while uploading file using multipart/form-data android 使用 enctype=multipart/form-data 上传文件时出错,错误是上传的文件不是 multipart - error while file uploading using enctype=multipart/form-data , the error is the file bring uploaded is not multipart multipart / form-data端点是否在服务器上创建临时文件 - Does multipart/form-data endpoint create temporary file on server 如何使用multipart / form-data在服务器中上传文件? - how to upload a file in server using multipart/form-data? 使用Camel上传多部分表单数据文件 - Multipart form-data file upload with Camel 通过多部分表单数据上传时如何知道文件大小? - How to know the file size when uploading via multipart form-data? 如何通过Java中的多部分表单数据上载时如何知道文件数 - How to know the file count when uploading via multipart form-data in java 使用Java上传具有multipart / form-data的zip文件时丢失字节 - Missing bytes when uploading zip file with multipart/form-data using java 使用改造将文件作为多部分/表单数据上传会产生 400 错误代码 - Uploading a file as multipart/form-data using retrofit gives 400 errorcode 在多部分/表单数据请求中上传文件时,Jersey引发ParseException - Jersey throws ParseException when uploading file in multipart/form-data request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM