Browse and download files with Flex, Spring and BlazeDS

This example will show how to get a list of all files and folders from a specific directory on the server, display them in the client’s application, browse these directories and/or download specific files.

So you may see that in the previous post I used Flex 4. I really wanted to create this example also with Flex 4, but I had problems with creating an itemRenderer for DataGrid, even found about this MXDataGridItemRenderer but still. I would appreciate if someone would comment about how to get over this. But whatsoever the example that I’m going to show here is created with Flex 3.5 and we all know how cool is it 🙂

This time we will start with the Spring implementation. So first we have this variable

This will keep track of our current directory, as we will browse the content from the client application. I’ve taken a note from Helen Neely on my previous post and now the path is OS independent and it points to the user’s home directory.

This method takes all the files and folders that are in the current directory that are not hidden (personal likeness) adds them in an ArrayList and returns the list. You can see that here we are creating new objects of type FileInfo, that is just a small class I wrote that has properties like name, size, isDir and data . There is also a corresponding to this class in the Flex project so we can map them.

Basically this creates a new FileInputStream for the file specified by the current directory and filename and reads it’s data in a array of bytes and then we return a new FileInfo instance that holds these bytes.

Having these methods we are ready to write our client application.
On creation complete we call

remoteBrowseDownload.listFiles();

place a DataGrid and for it’s dataProvider bind to the last result of this operation

We are doing a simple check whether this file is already downloaded and if it’s not we call the downloadFile method from our service with only the name of the file and add it in this downloadedFiles array that holds all of our downloaded files. You can see how fast the data is transfered, this is thanks to BlazeDS and AMF.

As this downloading could take longer (depending on the file size), we provide an event handler for the result., that just set the flag isDownloaded to true.

When files are being downloaded we display them in another grid with a progress bar and when the download completes, a button “save” appears to allow the user to save the file on his file system. To save a file we use the FileReference.save.

Share this:

Like this:

Related

Post navigation

16 comments

Looks amazing ! Together with your previous post, it creates a complete picture of handling file uploads/downloads with Flex/Spring/BlazeDS . It would be really great, if you can create your examples with Maven 2 , so that NetBeans users like me could easily reuse them 🙂

Thanks for your comment! I've looked on your suggestion, and now the Eclipse projects can be built with Maven 2, but only the Java ones. You can see the download links on the endings of this and the previous (file upload) posts. As with Flex for now you can build it only with Flex/Flash Builder. I think that later I could write a post about building Flex apps with Maven 2

Α high quality cameга for a νeгy attractive price oг juѕt a bad quality рicture? Discover on the full review at httр://reνіeωs.top-infοrmation.net/canon-рοwеrshot-ѕx50-hs-гeviеw/Take a look at my web-sitehowluciddreamtonight.wordpress.com

A high quality сameгa foг a very attrаctive pricе or juѕt a bad quality pictuгe?Dіscover on the full гeviеw at http://revіewѕ.top-informatіon.net/canon-рοwershot-sx50-hs-revіew/Also see my web site :: claninglaminatefloors.com

Having trouble losing weight? How about tаκіng a look at what is cοnsіdеrеd to be a fat burner in а bottle?Check οur guiԁe οn how to uѕe Rapberrу Ketones аnd gеt them fоr the best prіce at http://rasρberryketones.heaгtdata.nеt/My blog postBuy 3D Glasses

Getting a good HD ΤV has nеνer been easier. Discover the right mоdel for you and уour poсket with our reνіew at http://reviews.top-information.net/samsung-un40eh6000-review/Feel free to surf my web blog :: Allthebestproducts.Net