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:
- Uploading a file stores the File in a database table called FileData
- Uploading a file ALSO stores the file in a folder of your site /File.Example/Upload to demonstrate how to store the file
- 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.
- 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
- The Files are listed after upload due to the query of the FileData table
- Checking the boxes on the left of the filenames and clicking DOWNLOAD to get a full version of the compressed files.
- If one file is selected, the returned result is the single uncompressed file (from the database)
- 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.
- 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.