views:

340

answers:

1

I managged to upload files on app-engine by using the following example

http://stackoverflow.com/questions/1513603/how-to-upload-and-store-an-image-with-google-app-engine-java

and

http://www.mail-archive.com/[email protected]/msg08090.html

The problem is, I am sumitting 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

name = request.getParameter("name");

Why it is so? Is there a way to retrieve text field value?

+1  A: 

You have to go through the FileItemIterator. In the example you mentioned, only the image is processed (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=1045507 for more details.

rochb
Thanks.. It works...
Manjoor