在 GAE 上使用 apache fileupload

发布于 2024-11-02 23:24:06 字数 524 浏览 1 评论 0原文

我在 java 服务器端应用程序中使用 Apache Commons FileUpload ,该应用程序具有 html 表单fields :

  1. 目的地字段,将填写目的地邮箱的电子邮件地址
  2. 带有发件人消息的消息文本
  3. A <输入类型=文件...用于上传照片的字段。我可以接收上传的文件(作为流),但是

我想如何在 GAE 上上传这个应用程序。 我可以接收上传的文件(作为流,使用 org.apache.commons.fileupload.FileItemStream)。

我也想接收输入文本字段(即 1)和 2)) - 由应用程序的用户完成)

我想使用 org.apache.commons.fileupload.FileItem 访问这些文本字段,但我收到 java.rmi.server.UID 是一个受限类

I use Apache Commons FileUpload in a java server-side app that has a html form with fields :

  1. A destination fied that will be filled with email address of the destination mailbox
  2. A message text with a message of the sender
  3. A < input type=file ... field for uploading a photo. I can receive uploaded file (as a stream) but how

This app I want to upload on GAE .
I can receive uploaded file (as a stream , using org.apache.commons.fileupload.FileItemStream).

I want to receive too input textfields (i.e. 1) and 2)) - completed by the user of app)

I want to access these using org.apache.commons.fileupload.FileItem but I receive java.rmi.server.UID is a restricted class

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

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

发布评论

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

评论(2

听风念你 2024-11-09 23:24:06

您应该使用 FileItemIteratorApache Commons FileUpload

import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import java.io.InputStream;
..
public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    try {
      ServletFileUpload upload = new ServletFileUpload();
      res.setContentType("text/plain");

      FileItemIterator iterator = upload.getItemIterator(req);
      while (iterator.hasNext()) {
        FileItemStream item = iterator.next();
        String name = item.getFieldName();
        InputStream stream = item.openStream();

        if (item.isFormField()) {
          //regular form field
          resp.getWriter().println(("Form:" + name + " : " + Streams.asString(stream));
        } else {
          //fileform field 
          resp.getWriter().println(("File:" +name + " : " + item.getName());
        }

      }
    } catch (Exception ex) {
      throw new ServletException(ex);
    }
}

You should use the FileItemIterator of the Apache Commons FileUpload.

import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import java.io.InputStream;
..
public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    try {
      ServletFileUpload upload = new ServletFileUpload();
      res.setContentType("text/plain");

      FileItemIterator iterator = upload.getItemIterator(req);
      while (iterator.hasNext()) {
        FileItemStream item = iterator.next();
        String name = item.getFieldName();
        InputStream stream = item.openStream();

        if (item.isFormField()) {
          //regular form field
          resp.getWriter().println(("Form:" + name + " : " + Streams.asString(stream));
        } else {
          //fileform field 
          resp.getWriter().println(("File:" +name + " : " + item.getName());
        }

      }
    } catch (Exception ex) {
      throw new ServletException(ex);
    }
}
软甜啾 2024-11-09 23:24:06

看看这个:Google App Engine和 FileUpload

您无法直接写入 GAE 中的文件系统,但请查看 GAEVFS,它使用数据存储和内存缓存来模拟文件系统。

Take a look at this: Google App Engine and FileUpload

You can't write directly to the filesystem in GAE, but take a look at GAEVFS, which uses the datastore and memcache to emulate a filesystem.

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