Apache Commons Fileupload / Tomcat 无法处理 out.flush()

发布于 2024-08-08 08:18:49 字数 979 浏览 2 评论 0原文

有谁知道一种解决方法,如果您尝试刷新 servlet 输出流,apache commons fileupload 会抛出以下异常?

FileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly

基本上,我的代码循环使用 apache commons fileupload 上传的每个文件,然后尝试 out.flush() 有关每个文件的一些统计信息。即:

    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List<FileItem> items = upload.parseRequest(request);

    for(FileItem field : items) {
        if (!field.isFormField() && field.getName().length()>0 && field.getName().getSize()>0) {
            ArticleImport helper = new ArticleImport(new ArticleImportResponder(user,out));
            // This helper object uses out.flush() to provide feedback to the user.
            helper.process(field.getInputStream(), user);
            }
        }
    }

在Apache Tomcat 6.0.20中不会出现该问题,但在早期版本中确实会出现该问题。

Does anyone know of a workaround whereby if you are trying to flush the servlet output stream, apache commons fileupload throws the following exception?

FileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly

Basically I have code that loops through each file uploaded using apache commons fileupload, and then am trying to out.flush() some stats about each file. ie:

    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List<FileItem> items = upload.parseRequest(request);

    for(FileItem field : items) {
        if (!field.isFormField() && field.getName().length()>0 && field.getName().getSize()>0) {
            ArticleImport helper = new ArticleImport(new ArticleImportResponder(user,out));
            // This helper object uses out.flush() to provide feedback to the user.
            helper.process(field.getInputStream(), user);
            }
        }
    }

The problem does not occur in Apache Tomcat 6.0.20, but it does occur in earlier versions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻风 2024-08-15 08:18:49

不幸的是,这是一个已知的错误,除了确保您使用至少 6.0.20 之外,您对此无能为力。

您可以检测正在运行的 tomcat 版本,并使用它来确定是否可以使用以下调用使用 out.flush() :

javax.servlet.ServletContext.getServerInfo();

Unfortunately this is a known bug, there is nothing you can do about it except ensure that your using at least 6.0.20.

You could detect which version of tomcat is running and use that to determine if you can use out.flush() using the following call:

javax.servlet.ServletContext.getServerInfo();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文