I implemented a dynamic upload component in Tapestry using the sfwupload library and the Tapestry Upload module.
http://swfupload.org/ This flash library exposes an API in JavaScript that expects a URL to handle the upload. I used the following approach in my Tapestry component: * Construct actionLink and pass it to the JavaScript for the component * Initialize swfupload library with actionLink url and other callback handlers (this will also draw the upload button in flash) * Create OnEvent handler for the actionLink that will handle the upload from the client * Use MupltipartDecoder service from Tapestry Upload project to receive the file as an UploadedFile (multipartDecoder.getFileUpload("Filedata")) * The OnEvent can then return a JSONObject that will be handled by the sfupload success handler (upload_success_handler). This might contain something like the src to the preview. * Swfupload has built in error handling for things like file size, valid file extension, etc. Since the error detection is done in the flash layer and handled by the javaScript I implemented the JavaScript error handler to trigger an ajax request with the error code so that this can be resolved server side. Otherwise all localized strings for error handling would have to be passed to the swfupload JavaScript init. Adam -----Original Message----- From: Andrea Chiumenti [mailto:[email protected]] Sent: Friday, March 19, 2010 12:47 AM To: Tapestry development Subject: Re: Upload component vs. Ajax Form Submit Howard, as already said, there are two possibilities, one via flash the other via iframe :), all this if you consider a 'low level' coding. The other solution is using dojotoolkit or similar frameworks, that hide such decision. For example my tapestry-jfly.sourceforge.net that maps T5.1 over www.dojotoolkit.org http://www.dojotoolkit.org/api/dojox/form/FileInput.html kiuma 2010/3/19 Kalle Korhonen <[email protected]> > The typical non-Flash way is to do the file upload in an iframe. The > iframe doesn't have to contain more than a simple form with a single > file field. There's some trickery involved getting the UI to work > seamlessly and synchronizing the backend, especially if you need it to > look like it operates together with some other forms and form fields, > but I'm sure you are more than capable to handle it :) I recall > building an iframe-based upload component for Tapestry 4 at some > point. > > Kalle > > > On Thu, Mar 18, 2010 at 4:38 PM, Howard Lewis Ship <[email protected]> > wrote: > > Does anyone have any idea where to start with getting a file upload to > > work as part of an Ajax update? > > > > Ideally, the client side would be able to read the file contents and > > pass those up in the POST as a multipart/mime stream. > > > > However, the JavaScript file elements are carefully guarded against > > any kind of JavaScript behaviors, as a security concern (a valid one). > > > > I'm not sure how other sites manage this; I think they may use an > > embedded Flash movie? Any pointers would be most useful. > > > > -- > > Howard M. Lewis Ship > > > > Creator of Apache Tapestry > > > > The source for Tapestry training, mentoring and support. Contact me to > > learn how I can get you up and productive in Tapestry fast! > > > > (971) 678-5210 > > http://howardlewisship.com > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
