Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App-Engine (Java) File Upload

I managed to upload files on App-Engine by using the following example:

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

name = request.getParameter("name");

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

like image 864
Manjoor Avatar asked Apr 26 '10 08:04

Manjoor


1 Answers

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.

like image 65
rochb Avatar answered Sep 30 '22 00:09

rochb