MENU
Table of contents

Dynamsoft.FileUploader

Methods


Init

Syntax

/**
 * Initialize and create a FileUploader instance.
 * @param URL Specify a path to retrieve the FileUploader library.
 * @param successCallback A callback function that is executed if the request succeeds.
 * @param failureCallback A callback function that is executed if the request fails.
 * @argument uploadManager A FileUploader instance.
 * @argument errorCode The error code.
 * @argument errorString The error string.
 */
Init(
    URL: string,
    successCallback: (
        uploadManager: UploadManager
    ) => void,
    failureCallback: (
        errorCode: number,
        errorString: string
    ) => void
): void;

Usage notes

The FileUploader library is installed with Dynamsoft Service by default, therefore, URL can be left empty “”.


CreateJob

Syntax

/**
 * Create an upload job.
 */
CreateJob(): Job;

interface Job {
    /**
     * Specify the block size (in bytes). By default, it's 10240.
     */
    BlockSize: number;
    /**
     * Specify the file name.
     */
    FileName: string;
    /**
     * Specify the fields in the HTTP Post Form.
     */
    FormField: FormField;
    /**
     * Specify custom HTTP Post request headers.
     * Example: job.HttpHeader["Content-Type"] = "text/plain";
     */
    HttpHeader: object;
    /**
     * Return the Http version.
     */
    readonly HttpVersion: string;
    /**
     * A callback triggered when the job succeeds.
     * @argument job Specify the job.
     * @argument errorCode The error code.
     * @argument errorString The error string.
     */
    OnRunFailure: (
        job: Job,
        errorCode: number,
        errorString: string
    ) => void;
    /**
     * A callback triggered when the job succeeds.
     * @argument job Specify the job.
     */
    OnRunSuccess: (job: Job) => void;
    /**
     * A callback triggered multiple times during the upload.
     * @argument job Specify the job.
     * @argument percentage Return the percentage.
     */
    OnUploadTransferPercentage: (
        job: Job,
        percentage: number
    ) => void;
    /**
     * Specify the URL of the script to receive the upload.
     */
    ServerUrl: string;
    /**
     * Specify the main content of the job, i.e. the file(s).
     */
    SourceValue: SourceValue;
    /**
     * Specify the number of threads (<=4) for the upload.
     */
    ThreadNum: number;
    /**
     * Return the version of the job.
     */
    readonly Version: number;
}
interface SourceValue {
    /**
     * Specify the block size. By default, it's 10240.
     * @param source A URL to specify the content of the file.
     * Normally it's generated by {GenerateURLForUploadData()}
     * @param name Specify the name of the file.
     * @param key Specify the key of the file in the request. This key can be used to retrieve the file content in server-side scripts.
     */
    Add: (
        source: string,
        name: string,
        key ? : string
    ) => void;
}
interface FormField {
    /**
     * Specify the block size. By default, it's 10240.
     * @param key Specify the key of the field.
     * @param value Sepcify the value of the field.
     */
    Add: (
        key: string,
        value: string
    ) => void;
}

Run

Syntax

/**
 * Start uploading (processing the specified job).
 * @param job Specify the job.
 */
Run(job: Job): boolean;

Cancel

Syntax

/**
 * Cancel a job.
 * @param job Specify the job.
 */
Cancel(job: Job): boolean;

CancelAllupload

Syntax

/**
 * Cancel all jobs.
 */
CancelAllUpload(): boolean;

Usage notes

Cancel() or CancleAllUpload() should be called in the event OnUploadTransferPercentage.

Example

var dsUploadManager;
Dynamsoft.FileUploader.Init('', function(obj) {
    dsUploadManager = obj;
    var job = dsUploadManager.CreateJob();
    job.OnUploadTransferPercentage = FileUpload_OnUploadTransferPercentage;
    dsUploadManager.Run(job);

    function FileUpload_OnUploadTransferPercentage(job, iPercentage) {
        console.log('job cancelled!')
        dsUploadManager.Cancel(job);
    }
}, function() {});

Is this page helpful?

YesYes NoNo

In this article:

latest version

    © 2003–2020 Dynamsoft. All rights reserved.
    Privacy Statement / Site Map / Home / Purchase / Support