Thanks for Downloading Dynamic Web TWAIN 30-Day Trial!
Your download will start shortly. If your download does not begin, click here to retry.
FileUploader Module
The File Uploader is an independent component that is dedicated to file uploading. » HTTP with the File Uploader
Dynamsoft.FileUploader
Init()
Initialize and create a FileUploader instance.
Syntax
Init(
URL: string,
successCallback: (uploadManager: UploadManager) => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
Parameters
URL
: Specify a path to retrieve the FileUploader library.
successCallback
: A callback function that is executed if the request succeeds.
uploadManager
: A FileUploader instance. Please refer toUploadManager
.
failureCallback
: A callback function that is executed if the request fails.
errorCode
: The error code.errorString
: The error string.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Example
var dsUploadManager;
Dynamsoft.FileUploader.Init(
"",
function (obj) {
dsUploadManager = obj;
},
function () {}
);
Usage notes
The FileUploader library is installed with Dynamsoft Service by default, therefore, URL
can be left empty “”.
UploadManager
Methods
CreateJob() |
Run() |
Cancel() |
CancelAllUpload() |
CreateJob()
Create an upload job.
Syntax
CreateJob(): Job;
Please refer to Job
.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Run()
Start uploading (processing the specified job).
Syntax
Run(job: Job): boolean;
Parameters
job
: Specify the job.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Cancel()
Cancel a job.
Syntax
Cancel(job: Job): boolean;
Parameters
job
: Specify the job.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
CancelAllupload()
Cancel all jobs.
Syntax
CancelAllUpload(): boolean;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
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 () {}
);
Job
Properties
BlockSize |
FileName |
FormField |
HttpHeader |
HttpVersion |
ServerUrl |
SourceValue |
ThreadNum |
Version |
Events
OnUploadTransferPercentage |
OnRunSuccess |
OnRunFailure |
BlockSize
Specify the block size (in bytes). By default, it’s 10240.
Syntax
BlockSize: number;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
FileName
Specify the file name.
Syntax
FileName: string;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
FormField
Specifies extra fields to be uploaded in the same HTTP post.
Syntax
FormField: FormField;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Usage notes
Use the Add()
method of the Object to add fields for uploading. Please refer to FormField
.
Example
job.FormField.Add("customField", "FormFieldValue");
HttpHeader
Specifies headers in the the HTTP Post Request of the upload job. For example: job.HttpHeader["Content-Type"] = "text/plain";
Syntax
HttpHeader: object;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Usage notes
By default, HttpHeader is an empty object. If left as it is, default headers are used. Otherwise, the headers set by this property will be added to the HTTP Post Request or replace existing ones with the same names.
HttpVersion
Return the Http version.
Syntax
readonly HttpVersion: string;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
ServerUrl
Specifies the target of the HTTP Post Request of the upload job. This typically is a file on the server. For example: job.ServerUrl = 'http://www.dynamsoft.com/ScanAndUpload/Actions/SaveToFile.aspx';
Syntax
ServerUrl: string;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
SourceValue
Specifies the files to be uploaded and the name for it. The files are specified by URLs which can be created with the method GenerateURLForUploadData()
.
Syntax
SourceValue: SourceValue;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Usage notes
Use the Add()
method of the Object to add data for uploading. Please refer to SourceValue
.
Example
job.SourceValue.Add(url, fileName);
ThreadNum
Specify the number of threads (<=4) for the upload.
Syntax
ThreadNum: number;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Version
Return the version of the job.
Syntax
readonly Version: number;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
OnUploadTransferPercentage
The event is triggered during the execution of an upload job. It has a parameter which specifies the percentage of the completion of the job.
Syntax
OnUploadTransferPercentage: (
job: Job,
percentage: number
) => void;
Parameters
job
: A job object.
sPercentage
: The percentage of the completion of the job.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Example
job.OnUploadTransferPercentage = FileUpload_OnUploadTransferPercentage;
function FileUpload_ OnUploadTransferPercentage (job, sPercentage){
console.log(sPercentage);
}
OnRunSuccess
The event is triggered when an upload job completes successfully.
Syntax
OnRunSuccess: (job: Job) => void;
Parameters
job
: A job object.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Example
job.OnRunSuccess = FileUpload_OnRunSuccess;
function FileUpload_OnRunSuccess(job) {
alert(" upload completed ");
}
OnRunFailure
The event is triggered when an upload job completes successfully.
Syntax
OnRunFailure: (
job: Job,
errorCode: number,
errorString: string
) => void;
Parameters
job
: A job object.
errorCode
: The error code.
errorString
: The error string.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v14.0+ | v14.0+ | v14.0+ | v14.0+ |
Example
job.OnRunFailure = FileUpload_OnRunFailure;
function FileUpload_OnRunFailure(job, errorCode, errorString) {
alert(errorString);
}