本文介绍了在Apache Tapestry页面访问上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是Apache Tapestry v5.3.7,我已经在表单中使用了正常的Tapestry上传组件。为了更好的用户体验,我现在尝试在没有任何形式的情况下将Dropzone.js集成到普通的Tapestry页面中。 JavaScript集成工作正常。上传的文件数据传输到我的服务器与一个post请求,我可以访问请求的所有参数。
我现在的问题是如何访问二进制文件上传文件的数据(可能是InputStream)将它们保存在我的系统中?我已经注入了http请求,但getInputStream返回一个空的流。
感谢您的任何建议
/ ** java页面的代码片段* /
...
@Inject
protected HttpServletRequest _request;
public void onActivate(String rowId){
String fileName = _request.getParameter(file);
try {
InputStream is = _request.getInputStream();
//如果我读取它是否返回-1
// :-(
doSomeSaveStuff(is); //虚拟代码
}
catch(Exception e){
e.printStackTrace();
}
}
...
$ p 解决方案
在他的Tapestry魔术博客上,他整合了一个不同的文件上传器库和Tapestry,我猜你的答案将会在那里。
I'm using Apache Tapestry v5.3.7 and I already use the normal Tapestry upload component in a form. For a better user experience I try now to integrate Dropzone.js in a normal Tapestry page without any form. The JavaScript integration works fine. The uploaded file data are transferred to my server with a post request and I can access the request with all of its parameters.
My question is now how can I access the binary data of the uploaded file (maybe as InputStream) to save them in my system? I already injected the http request but getInputStream returns a empty stream.
Thanks for any suggestions
/** Code snippet of page java part */
...
@Inject
protected HttpServletRequest _request;
public void onActivate (String rowId) {
String fileName=_request.getParameter("file");
try {
InputStream is=_request.getInputStream();
// if I do read from is it returns -1
// :-(
doSomeSaveStuff(is); // dummy code
}
catch(Exception e) {
e.printStackTrace();
}
}
...
解决方案
Taha has a blog post here on his Tapestry Magic blog he integrates a different file uploader library with Tapestry. I'm guessing your answer will be there.
这篇关于在Apache Tapestry页面访问上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!