背景
我有一个简单的html表单:
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type="hidden" id="p" name="p" />
<input type="hidden" id="n" name="n" />
<input type="file" class="upload-file" id="file" name="file" />
<textarea id="o" name="o"></textarea>
<button type="submit" >Send</button>
</form>
<script>
$(function(){
var fileInput = $('.upload-file');
$('.upload-form').submit(function(e){
$("#n").val($('input[type=file]').val());
if(!fileInput.get(0).files.length){
alert('Select a file');
return false;
}
});
});
</script>
简单易用的消费者:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response upload(@MultipartForm FormDTO form) {
form.getData(); //<-- breakpoint here
}
问题
尝试上传16KB以下的文件(不会遇到断点):
WARN [org.apache.james.mime4j.parser.MimeEntity] Unexpected end of headers detected. Higher level boundary detected or EOF reached.
WARN [org.apache.james.mime4j.parser.MimeEntity] Invalid header encountered
WARN [org.apache.james.mime4j.parser.MimeEntity] Body part ended prematurely. Boundary detected in header or EOF reached.
ERROR Could find no Content-Disposition header within part.
大于16 KB的文件很好并正常工作(点击BreakPoint)。 (尝试逐个字符增加,直到大于16KB)。
考虑
Apache,Wildfly,Resteasy或JaxRS是否有最小的帖子大小阈值?
谢谢
附件:
大于16KB的Firebug POST文件(好!)
-----------------------------3380429991862985457771888012
Content-Disposition: form-data; name="p"
TOKEN
-----------------------------3380429991862985457771888012
Content-Disposition: form-data; name="n"
-----------------------------3380429991862985457771888012
Content-Disposition: form-data; name="file"; filename="filename"
Content-Type: application/octet-stream
LARGE lorem ipsum TEXT OMMITED
-----------------------------3380429991862985457771888012
Content-Disposition: form-data; name="o"
-----------------------------3380429991862985457771888012--
小于16KB的Firebug POST文件(不错!)
-----------------------------10552095891001881326598189114
Content-Disposition: form-data; name="p"
TOKEN
-----------------------------10552095891001881326598189114
Content-Disposition: form-data; name="n"
-----------------------------10552095891001881326598189114
Content-Disposition: form-data; name="file"; filename="fileSmaller"
Content-Type: application/octet-stream
SMALLER lorem ipsum text OMMITED
-----------------------------10552095891001881326598189114
Content-Disposition: form-data; name="o"
-----------------------------10552095891001881326598189114--
如果File为&lt; 16KB:
,则测试非常糟糕且难看的解决方法用16KB字符(零)填充(javascript循环)隐藏的输入&#39; x&#39;并提交WORKS和小文件可以发送。 (当然不推荐)