0

我正在处理多个文件上传。上传多个文件时出现奇怪的问题。

案例:当我选择多个文件时,如果其中一个文件的大小与其他文件相比较大,则它不会提交给 servlet。我正在选择以下文件(图片)。我使用断点,一步一步去,发现它error.txt的大小0Bytes在servlet中。如果我通过选择正确上传来上传它。

其他文件很大时有同样的问题,它不是特定于error.txt。我刚把案子给你了

在此处输入图像描述

仅供参考:我正在使用gwtupload插件进行多次上传。这是项目的链接:https ://code.google.com/p/gwtupload


更新:

@Manolo 为什么你cont在 servlet 中使用变量?

 int cont = 0;
 for (FileItem item : sessionFiles) {
    if (false == item.isFormField()) {
       cont ++;
4

1 回答 1

0

经过大量尝试,我找到了解决方案,所以让我向您展示我在代码中出错的地方。

for (FileItem item : sessionFiles) {
      if (false == item.isFormField()) {
        try {
          /// Create a temporary file placed in the default system temp folder
          File file = File.createTempFile("upload-", ".bin");
          item.write(file);

          /// Save a list with the received files
          receivedFiles.put(item.getFieldName(), file);
          receivedContentTypes.put(item.getFieldName(), item.getContentType());

          /// Send a customized message to the client.
          response += "File saved as " + file.getAbsolutePath();

          // Below line is creating the problem.
          removeItem(request, item.getFieldName());

        } catch (Exception e) {
          throw new UploadActionException(e);
        }
      }
    }

removeItem(request, item.getFieldName());在处理后删除每个文件。不知何故,它删除了error.txt文件。我不知道为什么。但是在删除那条线之后。它对我有用。

于 2013-10-09T09:20:07.083 回答