Action: File Example

A full working example of using the File Action to manage files

By Kevin M Schreiner

September 18, 2009

This example demonstrates use of the File Action to Upload, Download, Store and retrieve files from the databsase, Delete Files and Folders, Transform thumbnail images, detect whether a file is an image and Compress groups of files together.

To get started, download the configuration example and MAKE SURE you are running OWS 2.1.17 or higher. A bug in earlier versions caused the Compression method to work incorrectly for FORM fields.

Next, because this configuration demonstrates interaction with the database to store files, you will need to execute the following statement in your site to allow for the example to create the records necessary.

CREATE TABLE FileData(FileID int identity(1,1),Filename varchar(255), MimeType varchar(255), Data image)

The configuration supports the following interaction:

  1. Uploading a file stores the File in a database table called FileData
  2. Uploading a file ALSO stores the file in a folder of your site /File.Example/Upload to demonstrate how to store the file 
  3. Uploading a file ALSO stores the file in a folder of your site /File.Example/Compressed to demonstrate how to compress a single file from the incoming form variable. 
  4. When the Uploaded file is an IMAGE, a scaled image with a width of 64 pixels and a height scaled based on the incoming size ratio is created in /File.Example/Thumbnails 
  5. The Files are listed after upload due to the query of the FileData table
  6. Checking the boxes on the left of the filenames and clicking DOWNLOAD to get a full version of the compressed files.
    1. If one file is selected, the returned result is the single uncompressed file (from the database)
    2. If more than one file is selected, the download result is a compressed library of all checked files. A final action deletes the Folder that was created to produce the compressed library.
  7. Clicking DELETE will delete all checked files (/Upload, /Compressed, /Thumbnails) and remove the record(s) from the database.

Now, import this configuration into OWS and hit Publish. Then drop in an OWS module and pick "Sample.Files.Upload/Download/Compress".

DOWNLOAD THE CONFIGURATION HERE

Comments are provided in the configuration to explain how each area works, as follows:

Handling the UPLOAD and download is provided within a Region, to make it easier to read. Take note of how the frmGo form value identifies what action is being performed.
Uploading and Downloading are a bit different. Upload takes the incoming frmFile value and stores the files, while Download checks to see how may items were selected and switches between returning a single file or the compressed library based on the result.
Finally, the delete condition identifies which file/files to delete and removes both the files, as well as the data records.
Average (4 Ratings):
 
Want to help out?
 
 

New York, NY • Baltimore, MD • Vienna, VA • St. Louis, MO • Seattle, WA • 410.327.0007 • info@R2Integrated.com

Bookmark & Share Bookmark and Share