This documentation is for the old version. Go to the latest Upload Suite docs

Handling Files Compression

Image Uploader can resize and compress images before the upload as well as send any files as ZIP archives. This feature is very convenient for mixed upload handling. Suppose that your application receives image files and documents, and you want to decrease the size of files selected for upload. Image Uploader gives you the ability to implement the needed functionality: you can resize all the images to the predefined dimensions before the upload, and upload them as JPEG files, and also compress documents to ZIP archives and upload them too.

Uploading Files and Thumbnails

Image Uploader can send two kinds of files to a server:

  • Original file. The file uploaded from a user's computer without any changes. To specify whether the original file should be uploaded or not use the UploadSourceFile property.
  • Thumbnail. In Image Uploader's terms, the thumbnail is a separate copy of the original file created by applying one of the supported compression modes. To set the thumbnail count and their parameters use the UploadThumbnail1XXX, UploadThumbnail2XXX, UploadThumbnail3XXX, and UploadThumbnailXXX properties. See the Resizing and Rotating Images topic for more detailed information about thumbnails settings.

Uploading Compressed Images and Files as Thumbnails

Image Uploader supports the following compression modes for the uploading thumbnails:

Jpeg

If a file selected for upload is an image, Image Uploader resizes this image to the specified dimensions and uploads it as JPEG file. Otherwise, if a file is non-image, Image Uploader uploads a system icon associated with the file. By default, this mode is applied to any file regardless of its extension. More information about image resizing before upload you can read in the Resizing and Rotating Images topic.

Zip

Image Uploader sends a ZIP archive of the original file.

Icon

Image Uploader sends a system icon associated with a file selected for the upload.

SourceFile

Image Uploader sends the original file.

To specify the compression modes for particular file types use these properties:

The value of these properties is the compression mode format string which consists of file masks=compression modes pairs separated by semicolon. Each pair includes the set of file masks and the set of compression modes separated by comma. In general, this string has the following syntax:

mask11,mask12,...=mode1,mode2,...;mask21,mask22,...=mode1,mode2,...;...

When Image Uploader prepares a POST request it parses the compression mode format string from the beginning to the end and extracts file masks=compression modes pairs. For each file selected for upload Image Uploader gives the first pair. If it finds the file mask in this pair corresponded to extension of the file, it applies the first appropriate compression mode from the compression set of this pair. Otherwise, if no appropriate file mask or compression mode found, Image Uploader checks the next pairs in the same manner.

Note

If there is no file mask corresponded to the original file extension or no appropriate compression mode Image Uploader sends an icon.

Samples of Compression Mode Format Strings

The following examples demonstrate how to configure the compression mode format string.

JavaScript
iu.addParam("UploadThumbnail1CompressionMode", "*.jpeg,*.jpg,*.tif,*.bmp,*.wbmp,*.png=Jpeg;*.doc=Zip;*.*=SourceFile");

If the string above is specified Image Uploader sends:

  • JPEG thumbnail if the original file is image;
  • ZIP archive if the original file is Microsoft Office document;
  • The original file if no file mask match.
JavaScript
iu.addParam("UploadThumbnail1CompressionMode", "*.*=Jpeg,Zip");

In this sample, Image Uploader sends either JPEG thumbnail or ZIP archive in the case when it is unable to create JPEG thumbnail for a uploading file (when the uploading file is non-image).

Saving Compressed Images and Files

Image Uploader sends thumbnails and compressed files in the ThumbnailX_N POST fields. Depending on the applied compression mode names of these thumbnails can be:

  • OriginalFileName.OriginalFileExtension_ThumbnailX.jpg - for Jpeg and Icon compression modes;
  • OriginalFileName.OriginalFileExtension_CompressedX.zip - for Zip compression mode;
  • OriginalFileName.OriginalFileExtension_SourceX.OriginalFileExtension - for SourceFile compression mode.

To determine the actually applied compression mode on the server side use the UploadFileXCompressionMode_N POST field which contains the compression mode of the Xth thumbnail of the Nth uploaded file.

The following example (in pseudocode) demonstrates how to save thumbnails and compressed files on the server side:

iterate through each file (i)
{
    //This value is taken from the Thumbnail1_i POST field
    file thumbnail1File
	
    //This value is taken from the UploadFile1CompressionMode_i POST field
    string compressionMode
	
    if (compressionMode == "Jpeg" || compressionMode == "Icon")
    {
            //...Process thumbnail1File as an image file...
    }
    
    if (compressionMode == "Zip")
    {
            //...Process thumbnail1File as a ZIP file...
    }
        
    if (compressionMode == "SourceFile")
    {
            //...Process thumbnail1File as a source file...
    }		
}

See Also

Reference

Manual