Uploading files from the browser

12 views
Skip to first unread message

Jeff Schwartz

unread,
May 22, 2010, 4:36:13 PM5/22/10
to gae...@googlegroups.com
Hi Guillaume, all,

Does Gaelyk support file uploading as I can't seem to find it in the docs. Is there a groovy/gaelyk way of doing this without having to implement a class derived from HttpServlet to route the request myself? Is there any sample code somewhere? Thanks in advance.
 
--
Jeff

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/gaelyk?hl=fr

Soren Aalto

unread,
May 22, 2010, 5:02:31 PM5/22/10
to gae...@googlegroups.com
I did this recently using the Apache commons file upload stuff,
I think this is the typical way to do file uploads, but I'd like to
hear if there's a better way.
--
Soren Aalto
Director: ICT
University of Zululand

Jeff Schwartz

unread,
May 22, 2010, 6:04:39 PM5/22/10
to gae...@googlegroups.com
Hi Soren,

If I have a multi-part form and the form's action is upload.groovy for instance, can I use the Apache libraries from within the upload.groovy script to process the muti-part form data?

Also, I need to allow users to upload image files which I will not allow to be larger than 4 meg. Do you think it is possible to implement this considering the request timeout constraints that appengine imposes or is this impossible on appengine?

Thanks in advance.

Jeff

2010/5/22 Soren Aalto <soren...@gmail.com>



--

Soren Aalto

unread,
May 23, 2010, 1:08:09 AM5/23/10
to gae...@googlegroups.com
I think Apache commons will handle all this -- but my caveat,
I only got as far as doing a file upload on the dev server and
haven't yet deployed anything to appengine.

The details of the multipart form/encodings, etc, are fairly
hidden to the API user...I just copied from some examples
in the documentation & it seemed to work -- I got a file
to upload, parsed the CSV and stored it in the datastore.

2010/5/23 Jeff Schwartz <jeffts...@gmail.com>

Guillaume Laforge

unread,
May 23, 2010, 3:59:57 AM5/23/10
to gae...@googlegroups.com
File upload with commons-fileupload sounds just fine.
It's standard servlet stuff, and Gaelyk doesn't provide anything
special in this area, as this is not something specific to GAE.

That said, perhaps we could create a plugin for something like that,
if that's possible, that way, people would have a sample they can rely
on?

Guillaume

2010/5/22 Soren Aalto <soren...@gmail.com>:
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Jeff Schwartz

unread,
May 23, 2010, 9:21:48 AM5/23/10
to gae...@googlegroups.com
I found an example of a Gaelyk groovlet that uses the Apache FileUtil libs at the following url: http://fbflex.wordpress.com/2010/05/03/manipulating-images-on-the-google-app-engine-with-gaelyk/

The above is a good example with all the steps needed to process a multipart form and obtain an image from it.

In the above example, the last thing it does is the following:
// set response type
095 response.setContentType( uploads['photo'].contentType )
096  
097 // render image out
098 sout << pic.imageData
099 

Since browsers will send a separate http request for each images tag it finds in the dom my intuition tells me then that the best way to handle these image request would be to create a dedicated groovlet that just renders the image indicated by the src attribute of the image tag. In a template I could encode the src attributes as follows:

<% users.each{ user -> %>
<img src="dedicatedimagerenderer.groovy?userid=user.userId>
<% } %>

and in the dedicated image rendering groovlet I can query for the user entity whose id is passed in params as userid and render its image property as follows:

// query the datastore to get the user whose userId = params.userid
// set  the request's contenttype appropriately
sout << user.thumbnailimage // render image data to sout

Does having a dedicated groovlet whose only function is to render the images to sout sound like a valid approach or is there a groovier way to do this?

Thanks in advance.

Jeff
--

Jeff Schwartz

unread,
May 23, 2010, 9:33:22 AM5/23/10
to gae...@googlegroups.com
By the way, I just read the max upload size is 1 meg which wont be a problem as they are only going to be thumbnails.

limcheekin

unread,
May 23, 2010, 11:15:28 AM5/23/10
to Gaelyk
Hi Jeff,

You may look into a project called appengine-java-io located at
http://code.google.com/p/appengine-java-io/.

Below is the project introduction:
Google App Engine doesn't support Java IO writing operation natively.
The VObject AppEngine Java-IO is an open source project that intend
to port gaevfs to java.io API to enable java.io classes support in
Google App Engine (GAE) with Metaprogramming capability of the Groovy
Programming Language.

The Live Demo support multiple file upload (each one < 1M) and written
in Grails, unluckily it is facing server 500 error at the moment. The
example using Apache commons file upload component and it's streaming
API.

Full disclosure here, I am the project owner of appengine-java-io, if
you are interest to the source code of the Live Demo. please do let's
me know.

Wish to hear from you soon!

// Chee Kin




On May 23, 9:33 pm, Jeff Schwartz <jefftschwa...@gmail.com> wrote:
> By the way, I just read the max upload size is 1 meg which wont be a
> problem as they are only going to be thumbnails.
>
> On 5/23/2010 1:08 AM, Soren Aalto wrote:
>
>
>
> > I think Apache commons will handle all this -- but my caveat,
> > I only got as far as doing a file upload on the dev server and
> > haven't yet deployed anything to appengine.
>
> > The details of the multipart form/encodings, etc, are fairly
> > hidden to the API user...I just copied from some examples
> > in the documentation & it seemed to work -- I got a file
> > to upload, parsed the CSV and stored it in the datastore.
>
> > 2010/5/23 Jeff Schwartz <jefftschwa...@gmail.com
> > <mailto:jefftschwa...@gmail.com>>
>
> >     Hi Soren,
>
> >     If I have a multi-part form and the form's action is upload.groovy
> >     for instance, can I use the Apache libraries from within the
> >     upload.groovy script to process the muti-part form data?
>
> >     Also, I need to allow users to upload image files which I will not
> >     allow to be larger than 4 meg. Do you think it is possible to
> >     implement this considering the request timeout constraints that
> >     appengine imposes or is this impossible on appengine?
>
> >     Thanks in advance.
>
> >     Jeff
>
> >     2010/5/22 Soren Aalto <soren.aa...@gmail.com
> >     <mailto:soren.aa...@gmail.com>>
>
> >         I did this recently using the Apache commons file upload stuff,
> >         I think this is the typical way to do file uploads, but I'd
> >         like to
> >         hear if there's a better way.
>
> >         On Sat, May 22, 2010 at 10:36 PM, Jeff Schwartz
> >         <jefftschwa...@gmail.com <mailto:jefftschwa...@gmail.com>> wrote:
>
> >             Hi Guillaume, all,
>
> >             Does Gaelyk support file uploading as I can't seem to find
> >             it in the docs. Is there a groovy/gaelyk way of doing this
> >             without having to implement a class derived from
> >             HttpServlet to route the request myself? Is there any
> >             sample code somewhere? Thanks in advance.
>
> >             --
> >             Jeff
> >             --
> >             Vous recevez ce message, car vous êtes abonné au groupe
> >             Google Groupes Gaelyk.
> >             Pour envoyer un message à ce groupe, adressez un e-mail à
> >             gae...@googlegroups.com <mailto:gae...@googlegroups.com>.
> >             Pour vous désabonner de ce groupe, envoyez un e-mail à
> >             l'adresse gaelyk+un...@googlegroups.com
> >             <mailto:gaelyk%2Bunsu...@googlegroups.com>.
> >             Pour plus d'options, consultez la page de ce groupe :
> >            http://groups.google.com/group/gaelyk?hl=fr
>
> >         --
> >         Soren Aalto
> >         Director: ICT
> >         University of Zululand
> >         --
> >         Vous recevez ce message, car vous êtes abonné au groupe Google
> >         Groupes Gaelyk.
> >         Pour envoyer un message à ce groupe, adressez un e-mail à
> >         gae...@googlegroups.com <mailto:gae...@googlegroups.com>.
> >         Pour vous désabonner de ce groupe, envoyez un e-mail à
> >         l'adresse gaelyk+un...@googlegroups.com
> >         <mailto:gaelyk%2Bunsu...@googlegroups.com>.
> >         Pour plus d'options, consultez la page de ce groupe :
> >        http://groups.google.com/group/gaelyk?hl=fr
>
> >     --
> >     --
>
> >     Jeff
> >     --
> >     Vous recevez ce message, car vous êtes abonné au groupe Google
> >     Groupes Gaelyk.
> >     Pour envoyer un message à ce groupe, adressez un e-mail à
> >     gae...@googlegroups.com <mailto:gae...@googlegroups.com>.
> >     Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse
> >     gaelyk+un...@googlegroups.com
> >     <mailto:gaelyk%2Bunsu...@googlegroups.com>.
> >     Pour plus d'options, consultez la page de ce groupe :
> >    http://groups.google.com/group/gaelyk?hl=fr
>
> > --
> > Soren Aalto
> > Director: ICT
> > University of Zululand
> > --
> > Vous recevez ce message, car vous êtes abonné au groupe Google
> > Groupes Gaelyk.
> > Pour envoyer un message à ce groupe, adressez un e-mail
> > à gae...@googlegroups.com.
> > Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse
> > gaelyk+un...@googlegroups.com.
> > Pour plus d'options, consultez la page de ce groupe :
> >http://groups.google.com/group/gaelyk?hl=fr
>
> --
> Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
> Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
> Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
> Pour plus d'options, consultez la page de ce groupe :http://groups.google.com/group/gaelyk?hl=fr

tomas lin

unread,
May 24, 2010, 9:09:00 AM5/24/10
to Gaelyk
The code in that blog post was copied from Mr. Haki's blog -
http://mrhaki.blogspot.com/2009/11/add-file-upload-support-to-groovlets-in.html

Personally, I would recommend using the blobstore API for this since
it is officially supported by google and means it won't break in the
future. It also has nice bindings into the imageservice.

http://code.google.com/appengine/docs/java/blobstore/overview.html

On 23 mai, 14:21, Jeff Schwartz <jefftschwa...@gmail.com> wrote:
> I found an example of a Gaelyk groovlet that uses the Apache FileUtil libs
> at the following url:http://fbflex.wordpress.com/2010/05/03/manipulating-images-on-the-goo...
> On Sun, May 23, 2010 at 3:59 AM, Guillaume Laforge <glafo...@gmail.com>wrote:
>
>
>
> > File upload with commons-fileupload sounds just fine.
> > It's standard servlet stuff, and Gaelyk doesn't provide anything
> > special in this area, as this is not something specific to GAE.
>
> > That said, perhaps we could create a plugin for something like that,
> > if that's possible, that way, people would have a sample they can rely
> > on?
>
> > Guillaume
>
> > 2010/5/22 Soren Aalto <soren.aa...@gmail.com>:
> > > I did this recently using the Apache commons file upload stuff,
> > > I think this is the typical way to do file uploads, but I'd like to
> > > hear if there's a better way.
>
> > > On Sat, May 22, 2010 at 10:36 PM, Jeff Schwartz <jefftschwa...@gmail.com
>
> > > wrote:
>
> > >> Hi Guillaume, all,
>
> > >> Does Gaelyk support file uploading as I can't seem to find it in the
> > docs.
> > >> Is there a groovy/gaelyk way of doing this without having to implement a
> > >> class derived from HttpServlet to route the request myself? Is there any
> > >> sample code somewhere? Thanks in advance.
>
> > >> --
> > >> Jeff
>
> > >> --
> > >> Vous recevez ce message, car vous êtes abonné au groupe Google
> > >> Groupes Gaelyk.
> > >> Pour envoyer un message à ce groupe, adressez un e-mail
> > >> à gae...@googlegroups.com.
> > >> Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse
> > >> gaelyk+un...@googlegroups.com<gaelyk%2Bunsu...@googlegroups.com>
> > .
> > >> Pour plus d'options, consultez la page de ce groupe :
> > >>http://groups.google.com/group/gaelyk?hl=fr
>
> > > --
> > > Soren Aalto
> > > Director: ICT
> > > University of Zululand
>
> > > --
> > > Vous recevez ce message, car vous êtes abonné au groupe Google
> > > Groupes Gaelyk.
> > > Pour envoyer un message à ce groupe, adressez un e-mail
> > > à gae...@googlegroups.com.
> > > Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse
> > > gaelyk+un...@googlegroups.com<gaelyk%2Bunsu...@googlegroups.com>
> > .
> > > Pour plus d'options, consultez la page de ce groupe :
> > >http://groups.google.com/group/gaelyk?hl=fr
>
> > --
> > Guillaume Laforge
> > Groovy Project Manager
> > Head of Groovy Development at SpringSource
> >http://www.springsource.com/g2one
>
> > --
> > Vous recevez ce message, car vous êtes abonné au groupe Google
> > Groupes Gaelyk.
> > Pour envoyer un message à ce groupe, adressez un e-mail à
> > gae...@googlegroups.com.
> > Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse
> > gaelyk+un...@googlegroups.com<gaelyk%2Bunsu...@googlegroups.com>
> > .
> > Pour plus d'options, consultez la page de ce groupe :
> >http://groups.google.com/group/gaelyk?hl=fr
>
> --
> --
> Jeff
>
> --
> Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
> Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
> Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
> Pour plus d'options, consultez la page de ce groupe :http://groups.google.com/group/gaelyk?hl=fr

Soren Aalto

unread,
May 24, 2010, 9:40:44 AM5/24/10
to gae...@googlegroups.com
On Mon, May 24, 2010 at 3:09 PM, tomas lin <toma...@gmail.com> wrote:
Personally, I would recommend using the blobstore API for this since
it is officially supported by google and means it won't break in the
future. It also has nice bindings into the imageservice.

http://code.google.com/appengine/docs/java/blobstore/overview.html


Thanks -- that's really useful info...I'll definitely use this.



--
Soren Aalto
Director: ICT
University of Zululand

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages