GXT 中的文件上传会歧视某些文件类型
我们正在使用 GXT (EXT + GWT) 和 Apache commons 文件上传 servlet 实用程序。我们可以上传文件,但某些类型的文件无法上传,例如文本文件。即使文本文件的扩展名已更改,它们仍然不会上传。
在 FileUploadBase.parseRequest 方法中,这似乎是跳过输入流复制到文件系统的代码。当我断点文本文件的上传时,我尝试将 iter.hasNext() 代码加粗,该代码会跳过stream.copy 代码行。
任何建议将不胜感激!
提前致谢。
public List /* FileItem */ parseRequest(RequestContext ctx)
throws FileUploadException {
try {
FileItemIterator **iter = getItemIterator(ctx)**;
List items = new ArrayList();
FileItemFactory fac = getFileItemFactory();
if (fac == null) {
throw new NullPointerException(
"No FileItemFactory has been set.");
}
while (**iter.hasNext()**) {
FileItemStream item = iter.next();
FileItem fileItem = fac.createItem(item.getFieldName(),
item.getContentType(), item.isFormField(),
item.getName());
try {
Streams.copy(item.openStream(), fileItem.getOutputStream(),
true);
...
We are using GXT (EXT + GWT) and Apache commons file upload servlet utility. We have file uploads working but certain types are not uploaded, e.g., text files. Even if the text files have their extension changed they are still not uploaded.
In the FileUploadBase.parseRequest method this is the code that seems to be found to skip the input stream from being copied to the file system. I tried to bold the iter.hasNext() code that skips the stream.copy line of code when I break point the upload for a text file.
Any advice would be appreciated!
Thanks in advance.
public List /* FileItem */ parseRequest(RequestContext ctx)
throws FileUploadException {
try {
FileItemIterator **iter = getItemIterator(ctx)**;
List items = new ArrayList();
FileItemFactory fac = getFileItemFactory();
if (fac == null) {
throw new NullPointerException(
"No FileItemFactory has been set.");
}
while (**iter.hasNext()**) {
FileItemStream item = iter.next();
FileItem fileItem = fac.createItem(item.getFieldName(),
item.getContentType(), item.isFormField(),
item.getName());
try {
Streams.copy(item.openStream(), fileItem.getOutputStream(),
true);
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不会回答你的问题,但我可以发现有用的关于在 GWT 中上传文件的好库
GWTUpload 是一个用于将文件上传到 Web 服务器的库,显示进度条,其中包含有关进程的真实信息(文件大小、传输的字节数等)。它使用 ajax 请求向 Web 服务器询问上传进度。它有两个用 java 编写的组件,带有 servlet 和实用程序类的服务器端,以及使用 gwt 编译为 javascript 的客户端。 此处
This will not answer you question but I can find useful to tell about a good library for uploading files in GWT
GWTUpload is a library for uploading files to web servers, showing a progress bar with real information about the process (file size, bytes transferred, etc). It uses ajax requests to ask the web server for the upload progress. It has two components written in java, the server side with servlet and utility classes, and the client side that is compiled into javascript using gwt. here