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

Quick Start with Image Uploader JavaScript

Image Uploader JavaScript is a set of JavaScript classes intended to embed Image Uploader into a web page via <script type="text/javascript"> block. This JavaScript (aurigma.uploader.js) is a base for Image Uploader ASP.NET and Image Uploader PHP. Using the JavaScript library is more complicated: it requires configuring Image Uploader parameters manually and does not provide facilities to handle uploaded data server-side. However, it is more flexible and can be used with any HTTP-compliant server platform (not only ASP.NET or PHP).

Adding Image Uploader to Page

To add Image Uploader to the page you just need to perform the following steps:

  1. Copy the /Scripts folder to your web application. It can be found in Image Uploader installation folder (usually this is C:\Program Files\Aurigma\Image Uploader 7.0.37\Scripts).

  2. Link the aurigma.uploader.js file with the page which will host Image Uploader.

    JavaScript
    <script type="text/javascript" src="Scripts/aurigma.uploader.js"></script>
    
  3. Add JavaScript block to the position where you want to insert Image Uploader. Here create a new instance of the uploader class and specify its identifier via the uploader.id parameter.

    JavaScript
    <script type="text/javascript">
    var u = $au.uploader({
        id: 'Uploader1'
        
        // configure Image Uploader    
        
    });
    
    u.writeHtml();
    </script>        
    
  4. Then configure it in the way described in the following sections and call the uploader.writeHtml() method.

    Note:

    As soon as you call the uploader.writeHtml(), all necessary HTML code is inserted into the page at the current position. Alternatively, you can get the string with appropriate HTML code using the uploader.getHtml() method, and write it to the necessary position manually (maybe with some modifications).

Uploading Files

Here we discuss the use Image Uploader JavaScript by the example of a simple file catalog. Suppose that the catalog requires a user to upload files of various types and displays links to download these files. To implement this we should configure an uploader object and save uploaded files on a server. The sections below describe these steps in detail.

Configuring

To configure Image Uploader you should set properties of the uploader object. See the Image Uploader JavaScript Reference for the detailed information about available properties.

The properties accepting objects (such us uploader.uploadSettings or uploader.converters) should be specified in JSON format. Using this format you can also initialize all the uploader properties when creating it. Moreover, you can use the uploader.set(Object) method which accepts a JSON formatted string containing one or several properties definition.

Here is the source code of the main page of our catalog:

JavaScript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Image Uploader JavaScript Sample</title>
</head>
<body>
    <script type="text/javascript" src="Scripts/aurigma.uploader.js">  </script>
    <script type="text/javascript">
    var u = $au.uploader({
        id: 'Uploader1',
        width: '650px',
        height: '480px',
        licenseKey: 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXXX;YYYYY-YYYYY-YYYYY-YYYYY-YYYYY-YYYYYY',
        converters: [
            { mode: '*.*=SourceFile' }
        ], 
        uploadSettings: {
            actionUrl: 'Upload.aspx',
            redirectUrl: 'Catalog.aspx'
        }
    });
    
    u.writeHtml();
    </script>    
</body>
</html>

On this page we set a mandatory parameter, Image Uploader identifier, as well as optional parameters required by our file catalog. Here we specify server upload script and a page to which a user will be redirected when the upload successfully completes. To configure Image Uploader to send original files we used the uploader.converters property which accepts an array of converter objects. Each object specifies what will be uploaded (original file as is, thumbnail created from original image file, icon associated with original file, or original file compressed into ZIP archive) for each of the user-selected files. Since we need to upload only the original files, we set one converter with the SourceFile mode. Read more about converters in the Configuring Files to be Uploaded topic.

One more significant property is uploader.licenseKey which specifies trial or full license key. If license key is not set Image Uploader will not send files (the exception is usage of uploader on localhost domain). See the Evaluating and Registering Image Uploader topic for details.

Handling Upload

According to the catalog requirements, we save original files to the /Catalog folder. The way to implement it depends on your server platform. Find the detailed instructions and code samples on how to save uploaded files in the Saving Uploaded Files in ASP.NET and Saving Uploaded Files in PHP articles.

Displaying Uploaded Files

On the configuring step we set the uploadSettings.redirectUrl property. It specifies a page to which Image Uploader will redirect users after the upload is successfully completed. It would be convenient to list links to the uploaded files here. To implement this functionality we iterate through all the files stored in the /Catalog folder and display a link to each of them.

The script which generates this page depends on your server platform. For example, if you save uploaded files in ASP.NET, you can use the script listed in the Quick Start with Image Uploader ASP.NET topic. For PHP platform use the analogue from the Quick Start with Image Uploader PHP article.

Uploading Images

One more example of Image Uploader usage is an image gallery. Suppose, it requires a user to upload original images along with their downsized copies. This task can be divided into the same phases as the previous one.

Configuring

The configuration of the uploader object used for our image gallery is almost the same as for the file catalog described above.

JavaScript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Image Uploader JavaScript Sample</title>
</head>
<body>
    <script type="text/javascript" src="Scripts/aurigma.uploader.js">  </script>
    <script type="text/javascript">
    var u = $au.uploader({
        id: 'Uploader1',
        width: '650px',
        height: '480px',
        licenseKey: 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXXX;YYYYY-YYYYY-YYYYY-YYYYY-YYYYY-YYYYYY',
        converters: [
            { mode: '*.*=SourceFile' },
            { mode: '*.*=Thumbnail;*.*=Icon', thumbnailFitMode: 'Fit', thumbnailWidth: '120', thumbnailHeight: '120' }
        ], 
        uploadSettings: {
            actionUrl: 'Upload.aspx',
            redirectUrl: 'Gallery.aspx'
        }
    });
    
    u.writeHtml();
    </script>    
</body>
</html>

The difference is that we set an additional converter to specify a thumbnail which will be created for each image file and will be fitted to 120x120 pixels. For non-image files this converter will send icons. Read more about converters in the Configuring Files to be Uploaded topic.

Handling Upload

The gallery stores original images and their thumbnails in /Gallery and /Gallery/Thumbnails folders respectively. The way to implement it depends on your server platform. Find the detailed instructions and code samples on how to save uploaded files in the Saving Uploaded Files in ASP.NET and Saving Uploaded Files in PHP articles.

Displaying Uploaded Files

On the configuring step we set the uploadSettings.redirectUrl property. It specifies a page to which Image Uploader will redirect users after the upload is successfully completed. It would be convenient to display uploaded files here. To implement this functionality we iterate through all the previews stored in the /Gallery/Thumbnails folder and display each thumbnail as a link to its original image (original images are stored in the /Gallery folder).

The script which generates this page depends on your server platform. For example, if you save uploaded files in ASP.NET, you can use the script listed in the Quick Start with Image Uploader ASP.NET topic. For PHP platform use the analogue from the Quick Start with Image Uploader PHP article.

See Also

Reference

Manual