Not really what happens, apparently does not save the image (blob), or
email, or the idimage. because when you try to display it, is null.
This is the doGet
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String email = req.getParameter("email");
String bookid = req.getParameter("bookid");
BookImage imagen = getImage(email, bookid );
if (imagen != null && imagen.getImage() != null) {
Blob imageBlob = imagen.getImage();
// serve the first image
resp.setContentType("image/jpg");
resp.getOutputStream().write(imageBlob.getBytes());
} else {
// If no image is found with the given title,
redirect the user
// to
// a static image
resp.sendRedirect("images/no_image.png");
}
}
On 22 oct, 05:34, Didier Durand <[email protected]> wrote:
> Hi Erik,
>
> To check (and then limit) the format, you can extract the picture from
> the mail as a byte[] and then use this byte[] to create an image via
> ImagesService.makeImage(byte[]) and then do Image.getFormat() to see
> if you accept the format or not.
>
> regards
> didier
>
> On Oct 21, 1: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.