gpt4 book ai didi

java - App-Engine (Java) 文件上传

转载 作者:搜寻专家 更新时间:2023-10-30 19:45:22 24 4
gpt4 key购买 nike

我使用以下示例成功地在 App-Engine 上上传了文件:

How to upload and store an image with google app engine (java)

How to upload pics in appengine java

问题是,我正在提交其他字段以及文件字段,如下所示:

<form action="index.jsp" method="post" enctype="multipart/form-data">
<input name="name" type="text" value=""> <br/>
<input name="imageField" type="file" size="30"> <br/>
<input name="Submit" type="submit" value="Sumbit">
</form>

在我的 servlet 中,我在查询时得到 null

name = request.getParameter("name");

为什么会这样?有没有办法检索文本字段值?

最佳答案

您必须通过 FileItemIterator。在您提到的示例中,仅处理图像 (FileItemStream imageItm = iter.next();)。

// From the example: http://stackoverflow.com/questions/1513603/how-to-upload-and-store-an-image-with-google-app-engine-java
FileItemIterator iter = upload.getItemIterator(req);
// Parse the request
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
System.out.println("Form field " + name + " with value "
+ Streams.asString(stream) + " detected.");
} else {
// Image here.
System.out.println("File field " + name + " with file name "
+ item.getName() + " detected.");
// Process the input stream
...
}
}

参见 http://www.jguru.com/faq/view.jsp?EID=1045507了解更多详情。

关于java - App-Engine (Java) 文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2712011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com