Krystalware

SlickUpload Demos

» Overview Demonstrates the basics of SlickUpload. Selecting files, maximum file limit, file type validation, require files to be selected.
» FileNameGenerator How to control and generate server filenames for files as they are uploaded.
» Additional Fields How to add additional input fields for each selected file.
» Custom Progress Display custom progress information during a postprocessing step after files are uploaded.
» Localization How to localize the SlickUpload control.
» Modal Progress Show the progress display in a modal.
» Skinned Skin the file list and progress display.
» Upload to Amazon S3 How to upload to Amazon's Simple Storage Service with progress display.
» Upload to SQL Server Upload directly to a SQL Server, streaming with no memory usage.
Clustered» Use a StatusManager configuration to allow uploads with progress to a cluster/web farm/web garden.
» Custom UploadStreamProvider How to develop your own upload stream provider – this example shows how to zip files as they are uploaded.
» SimpleThe bare metal SlickUpload control, drag-dropped onto the page.

SQL Server Upload Sample

To see this sample in action, download the SlickUpload package and configure it for your environment.

NOTE: the maximum allowed request size for this sample is 1000 MB. If you attempt to upload files larger than this, you will recieve a oversized upload error which SlickUpload will handle gracefully. This is controlled by the maxRequestLength attribute of the httpRuntime key in the web.config file.

Configuration

Configuration for the SQL sample involves creating the file database and table and configuring SlickUpload to point at that database. To do this, perform the following steps:

  1. Create a new database, or select an existing database to use
  2. Open and run the SlickUploadFile.sql script in the SlickUpload distribution package root folder on the selected database
  3. Change the connection string in the uploadStreamProvider web.config section to point to the database selected above

Description

SlickUpload includes the capability to upload streaming directly to a SQL database, eliminating any in-memory copy of files as they are uploaded. This is accomplished by using the SqlClient UploadStreamProvider. To use this instead of the default File UploadStreamProvider, use an uploadStreamProvider web.config configuration section like the following:

<uploadStreamProvider provider="SqlClient"
    connectionString="server=.;uid=xxx;pwd=xxx;database=xxx;"
    table="SlickUploadFile"
    keyField="FileId" dataField="Data" fileNameField="FileName" />

You can use other table and field names by changing them in the database and setting them in the SlickUpload configuration. This configuration is the default, built around the provided SlickUploadFile.sql schema. Once the files are uploaded, you can update the records with additional info, select, manipulate, etc. just like any other database record.

To retrieve the data from the record while still maintaining the streaming interaction, use the SqlClientOutputStream class. Create an instance and read the data out from the stream, manipulating it or sending it to the client as you go. For example, here's how it is used in this sample:

public Stream GetDataStream()
{
    return new SqlClientOutputStream(_cnString, _table, _dataField, _keyField, _id);
}

The download file handler uses this method to get a stream, and then streams the file down to the client:

public void ProcessRequest(HttpContext context)
{
    int id = int.Parse(context.Request.QueryString["id"]);

    RepositoryFileCS file = RepositoryFileCS.GetById(id);

    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    context.Response.AddHeader("Content-Length", file.Length.ToString());
    context.Response.ContentType = "application/octet-stream";

    using (Stream dataStream = file.GetDataStream())
    {
        byte[] buffer = new byte[8192];

        int read;

        while ((read = dataStream.Read(buffer, 0, 8192)) > 0)
            context.Response.OutputStream.Write(buffer, 0, read);
    }
}