Instead of saving it in DataStore, I would recommend using BlobStore.

I do it something like this:


- Retrieve all data uploaded using BlobstoreService::getUploadedBlobs
- Do all the validation, as may be required (with other form data)
- if !valid
   => BlobstoreService::delete(...)
  else
   => Keep it saved in blob-store and continue



-Gaurav
www.mastergaurav.com


On Oct 21, 4:43 pm, erikzamith <[email protected]> wrote:
> Hello,
> I have an image that would save the user (email) and a idimagen.
> I use a form to send email and idimagen (Book). But do not persistence.
>
> I also want to know how to limit the types of images (jpg, png and gif
> only).
>
> This is my
>
> public class Upload extends HttpServlet {
> @Override
> public void doPost(HttpServletRequest request, HttpServletResponse res)
> throws ServletException, IOException {
>
> Long bookid = -4L;
> String email = "";
> Blob imageBlob = null;
> try{
> ServletFileUpload upload = new ServletFileUpload();
> FileItemIterator iter = upload.getItemIterator(request);
> while(iter.hasNext()){
> FileItemStream imageItem = iter.next();
> if(imageItem.isFormField()) {
> String name = imageItem.getFieldName();
> InputStream imgStream = imageItem.openStream();
>
> byte [] buffer = new byte[1024];
> int i=0;
> while(true) {
> int v = imgStream.read();
> if(v == 0 || v == -1)
> break;
> buffer[i] = (byte) v;
> i++;}
>
> String value = new String(buffer,0,i);
>
> if("bookid".equals(name)){
> bookid = Long.valueOf(value);
> System.out.println("bookid: "+bookid);}
>
> if("email".equals(name))
> email = value;
> System.out.println("email: "+email);} else {
>
> InputStream imgStream = imageItem.openStream();
> imageBlob = new Blob(IOUtils.toByteArray(imgStream));}
> }
>
> // construct our entity objects
>
> BookImage myImage = new BookImage(bookid, email, imageBlob);
>
> // persist image
> PersistenceManager pm = Commons.instance().getPersistenceManager();
> pm.makePersistent(myImage);
>
> // respond to query
> res.setContentType("text/plain");
> res.getOutputStream().write("OK!".getBytes());
>
> } catch(FileUploadException e){
>
> e.printStackTrace();
>
> }
> }
> }
>
> But when I show the picture, no picture, not saved any.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to