2010-04-26 37 views
14

tôi quản lý để tải lên các tập tin trên App-Engine bằng cách sử dụng ví dụ sau:App-Engine (Java) Tập tin Tải

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

How to upload pics in appengine java

Vấn đề là, tôi đang gửi các trường khác cùng với trường tệp như được liệt kê bên dưới:

<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> 

Trong servlet của tôi, tôi nhận được null khi truy vấn

name = request.getParameter("name"); 

Tại sao lại như vậy? Có cách nào để lấy giá trị trường văn bản không?

Trả lời

9

Bạn phải đi qua FileItemIterator. Trong ví dụ bạn đã đề cập, chỉ hình ảnh được xử lý (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 
     ... 
    } 
} 

Xem http://www.jguru.com/faq/view.jsp?EID=1045507 để biết thêm chi tiết.

+0

Cảm ơn .. Nó hoạt động ... – Manjoor