App-Engine (Java) 文件上传
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2712011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
App-Engine (Java) File Upload
提问by Manjoor
I managed to upload files on App-Engine by using the following example:
我使用以下示例设法在 App-Engine 上上传文件:
How to upload and store an image with google app engine (java)
and
和
How to upload pics in appengine java
The problem is, I am submitting other fields along with file field as listed below:
问题是,我正在提交其他字段以及文件字段,如下所示:
<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>
In my servlet, I am getting null when querying
在我的 servlet 中,查询时我得到了 null
name = request.getParameter("name");
Why it is so? Is there a way to retrieve text field value?
为什么会这样?有没有办法检索文本字段值?
采纳答案by rochb
You have to go through the FileItemIterator. In the example you mentioned, only the image is processed (FileItemStream imageItm = iter.next();).
您必须通过 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
...
}
}
See http://www.jguru.com/faq/view.jsp?EID=1045507for more details.
有关更多详细信息,请参阅http://www.jguru.com/faq/view.jsp?EID=1045507。

