Upload & Download

Methods
ClearAllHTTPFormField() FTPDownload()
FTPDownloadDirectly() FTPDownloadEx()
FTPUpload() FTPUploadAllAsMultiPageTIFF()
FTPUploadAllAsPDF() FTPUploadAsMultiPagePDF()
FTPUploadAsMultiPageTIFF() FTPUploadDirectly()
FTPUploadEx() HTTPDownload()
HTTPDownloadDirectly() HTTPDownloadEx()
HTTPUpload() HTTPUploadAllThroughPostAsMultiPageTIFF()
HTTPUploadAllThroughPostAsPDF() HTTPUploadThroughPost()
HTTPUploadThroughPostAsMultiPagePDF() HTTPUploadThroughPostAsMultiPageTIFF()
HTTPUploadThroughPostDirectly() HTTPUploadThroughPostEx()
SetHTTPFormField() SetUploadSegment()
SetHTTPHeader()
Properties
FTPPassword FTPPort
FTPUserName HttpFieldNameOfUploadedImage
HTTPPort HTTPPostResponseString
IfPASVMode IfShowCancelDialogWhenImageTransfer
IfSSL MaxUploadImageSize
Events
OnInternetTransferPercentage OnInternetTransferPercentageEx

Code example

The following code example demonstrates how to use the APIs above to perform basic uploading.

DWObject.HTTPUpload ('www.dynamsoft.com/SaveToFile.aspx?filename=001.pdf', [0,1],  EnumDWT_ImageType.IT_PDF, EnumDWT_UploadDataFormat.Binary, 'test.pdf', OnHttpUploadSuccess, OnHttpUploadFailure);
function OnHttpUploadSuccess (httpResponse, newIndices, _arguments) {
    console.log("HTTPResponseString: " + httpResponse);
}
function OnHttpUploadFailure (errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert("ErrorCode: " + errorCode+ "ErrorString: " + errorString + "HTTPResponseString: " + httpResponse);
}

Methods

ClearAllHTTPFormField()
Clears all the web form fields which will be sent to the server with the images when uploading.
Syntax .ClearAllHTTPFormField();
Parameters None
Return value boolean
Example
DWObject.ClearAllHTTPFormField(); 
Usage notes
Availability v5.0+
FTPDownload()
Downloads an image from a specified FTP server.
Syntax .FTPDownload(fTPServer, fTPRemoteFile, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
string fTPRemoteFile: the path of the file on the FTP server.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is downloaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be downloaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes Dynamic Web TWAIN processes the image format according to the extension of fTPRemoteFile.
Availability v4.0+
FTPDownloadDirectly()
Downloads a file from a specified FTP server directly without opening it in Dynamic Web TWAIN.
Syntax .FTPDownloadDirectly(fTPServer, fTPRemoteFile, localFile, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
string fTPRemoteFile: the path of the file on the FTP server.
string localFile: the local path for the downloaded file.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is downloaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be downloaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes Technically this method can download any file from the FTP server.
Availability v7.0+
FTPDownloadEx()
Downloads an image from a specified FTP server.
Syntax .FTPDownloadEx(fTPServer, fTPRemoteFile, imageType, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
string fTPRemoteFile: the path of the file on the FTP server.
EnumDWT_ImageType (int) imageType: the image format to be used.
Type Numeric Value
IT_BMP 0
IT_JPG 1
IT_TIF 2
IT_PNG 3
IT_PDF 4
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is downloaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be downloaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes
Availability v5.0+
FTPUpload()
Uploads the image of a specified index in the buffer to the FTP server in a specified image format.
Syntax .FTPUpload(fTPServer, sImageIndex, fTPRemoteFile, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
number sImageIndex: the index of the image in the buffer. The index is 0-based.
string fTPRemoteFile: the file name, path included.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes Dynamic Web TWAIN processes the image format according to the extension of fTPRemoteFile.
Availability v4.0+
FTPUploadAllAsMultiPageTIFF()
Uploads all the images in the buffer to a specified FTP server as a TIFF file.
Syntax .FTPUploadAllAsMultiPageTIFF(fTPServer, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
string fileName: the file name, including the path.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes
Availability v4.0+
FTPUploadAllAsPDF()
Uploads all the images in the buffer to a specified FTP server as a PDF file.
Syntax .FTPUploadAllAsPDF(fTPServer, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
string fileName: the file name, including the path to the file.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes
Availability v4.0+
FTPUploadAsMultiPagePDF()
Uploads the selected images in buffer to a specified FTP server as a PDF file.
Syntax .FTPUploadAsMultiPagePDF(fTPServer, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
string fileName: the file name, path included.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes
Availability v6.0+
FTPUploadAsMultiPageTIFF()
Uploads the selected images in the buffer to a specified FTP server as a TIFF file.
Syntax .FTPUploadAsMultiPageTIFF(fTPServer, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
string fileName: the file name, path included.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes
Availability v6.0+
FTPUploadDirectly
Upload any type of file to the server via FTP.
Syntax .FTPUploadDirectly(fTPServer, strLocalFile, fTPRemoteFile, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
string strLocalFile: the path of the local file.
string fTPRemoteFile: the file name, path included.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes
Availability v7.0+
FTPUploadEx()
Uploads the image of a specified index in buffer to the FTP server in a specified image format.
Syntax .FTPUploadEx(fTPServer, sImageIndex, fTPRemoteFile, imageType, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fTPServer: the FTP server.
number sImageIndex: the index of image in buffer. The index is 0-based.
string fTPRemoteFile: the file name, path included.
EnumDWT_ImageType (int) imageType: the format.
Type Numeric Value
IT_BMP 0
IT_JPG 1
IT_TIF 2
IT_PNG 3
IT_PDF 4
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
Usage notes
Availability v5.0+
HTTPDownload()
Downloads an image from a specified HTTP server.
Syntax .HTTPDownload(strHTTPServer, strHTTPRemoteFile, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the HTTP server.
string strHTTPRemoteFile: the file name, the path of the file on the HTTP server.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is downloaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be downloaded.
Please refer to the function prototype onsuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
/****Get image01.png from: http://www.dynamsoft.com/images/image01.png****/
DWObject.HTTPDownload('www.dynamsoft.com','/images/image01.png'); 
Usage notes If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v4.0+
HTTPDownloadDirectly()
Downloads a file from a specified HTTP server directly without opening it in Dynamic Web TWAIN.
Syntax .HTTPDownloadDirectly(strHTTPServer, strHTTPRemoteFile, localFile, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the HTTP server.
string strHTTPRemoteFile: the path of the file on the HTTP server, or the path to an action page (with necessary parameters) which gets and sends back the file stream to the client.
string localFile: the local path for the downloaded file.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is downloaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be downloaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
/*Get ducument.txt from: http://www.dynamsoft.com/files/ducument.txt*/
/*Save as 01.txt to: D:/*/
DWObject.HTTPDownloadDirectly('www.dynamsoft.com','/files/ducument.txt','D:/01.txt');

/*Get image02.jpg 
from: http://www.dynamsoft.com/images/GetImage.aspx?Index=2&Name=image02.jpg*/
/**Save as 02.jpg to: D:/temp/02.jpg**/
DWObject.HTTPDownloadDirectly('www.dynamsoft.com', 
'/images/GetImage.aspx?Index=2&Name=image02.jpg','D:/temp/02.jpg');
Usage notes Technically this method can download any file from the HTTP server.
If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v7.0+
HTTPDownloadEx()
Downloads an image from a specified HTTP server.
Syntax .HTTPDownloadEx(strHTTPServer, strHTTPRemoteFile, imageType, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the address of the HTTP server. For example: "www.dynamsoft.com", "localhost", "127.0.0.1".
string strHTTPRemoteFile: the path of the file on the HTTP server, or the path to an action page (with necessary parameters) which gets and sends back the image stream to the client.
EnumDWT_ImageType (int) imageType: the image format.
Type Numeric Value
IT_BMP 0
IT_JPG 1
IT_TIF 2
IT_PNG 3
IT_PDF 4
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is downloaded successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be downloaded.
Please refer to the function prototype OnSuccess or OnFailure.
Return value Boolean, only valid when used synchronously.
Example
/*Get image01.png from: http://www.dynamsoft.com/images/image01.png*/
DWObject.HTTPDownloadEx('www.dynamsoft.com','/images/image01.png',3);

/*Get image02.jpg from: 
http://www.dynamsoft.com/images/GetImage.aspx?Index=2&Name=image02.jpg*/
DWObject.HTTPDownloadEx('www.dynamsoft.com', 
'/images/GetImage.aspx?Index=2&Name=image02.jpg',1);
Usage notes If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v5.0+
HTTPUpload()
1. Uploads images of specified indices in the buffer to the HTTP server asynchronously.
1. Or uploads the form created by SetHTTPFormField.
Syntax 1. HTTPUpload(url, indices, enumImageType, dataFormat, fileName, asyncSuccessFunc, asyncFailureFunc);
2. HTTPUpload(url, indices, enumImageType, dataFormat, asyncSuccessFunc, asyncFailureFunc);
3. HTTPUpload(url, asyncSuccessFunc, asyncFailureFunc);
Parameters string url: specifies the url that the Post request is sent to. For example "https://www.dynamsoft.com/ActionPageName?filename=FileName".
Array indices: specifies the indices of images in buffer. The index is 0-based. If EnumDWT_ImageType is IT_BMP/IT_JPG/IT_PNG, since multi-page file is not possible, you can only specify one index.
EnumDWT_ImageType enumImageType: specifies the format of the file you want to upload as.
Type Numeric Value
IT_BMP 0
IT_JPG 1
IT_TIF 2
IT_PNG 3
IT_PDF 4
EnumDWT_UploadDataFormat dataFormat: specifies the data format, either EnumDWT_UploadDataFormat.Binary or EnumDWT_UploadDataFormat.base64.
Type Numeric Value
BINARY 0
BASE64 1
string fileName: specifies the file name.
<onHttpUploadSuccess function> asyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> asyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure.
Return value Boolean. This method is used asynchronously only. Even though it returns true doesn't mean that the upload is successful.
Example
DWObject.HTTPUpload('https://www.dynamsoft.com/SaveToFile.aspx', 
[0,1],  EnumDWT_ImageType.IT_PDF, EnumDWT_UploadDataFormat.Binary, 
'test.pdf', OnHttpUploadSuccess, OnHttpUploadFailure);
function OnHttpUploadSuccess (httpResponse, newIndices, _arguments) {
    console.log("HTTPResponseString: " + httpResponse);
}
function OnHttpUploadFailure (errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert("ErrorCode: " + errorCode+ "ErrorString: " + 
    errorString + "HTTPResponseString: " + httpResponse);
}
Usage notes This method is valid only in the HTML5 Edition from v12.0.
Availability v12.0+
HTTPUploadAllThroughPostAsMultiPageTIFF()
Uploads all the images in the buffer to a specified HTTP server as a single TIFF file.
Syntax .HTTPUploadAllThroughPostAsMultiPageTIFF(strHTTPServer, actionPage, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the name of the HTTP server. For example: "www.dynamsoft.com", "localhost", "127.0.0.1".
string actionPage: the relative path for the action page on the server. The action page will receive and process the uploaded image stream.
string fileName: the file name.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<onHttpUploadSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure.
Return value Boolean, only valid when used synchronously.
Example
function btnScan_onclick() 
{
    if (DWObject) {
        DWObject.SelectSource();
        DWObject.OpenSource();
        DWObject.IfDisableSourceAfterAcquire = true;
        DWObject.AcquireImage();
    }
}
// OnHttpUploadSuccess and OnHttpUploadFailure are callback functions.
function OnHttpUploadSuccess(httpResponse, newIndices, _arguments) {
    console.log('successful');
}
function OnHttpUploadFailure(errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert(errorString + httpResponse);
}

function btnUpload_onclick() 
{
    var strstrHTTPServer = location.hostname; //The name of the HTTP server. 
    var CurrentPathName = unescape(location.pathname);
    var CurrentPath = CurrentPathName.substring(0, 
    CurrentPathName.lastIndexOf("/") + 1);
    var strActionPage = CurrentPath + "SaveToFile.aspx";
    DWObject.IfSSL = false; // Set whether SSL is used
    DWObject.HTTPPort = location.port == "" ? 80 : location.port;

    
    // Upload all the images in the buffer to the 
    // HTTP server as a TIFF file asynchronously
    DWObject.HTTPUploadAllThroughPostAsMultiPageTIFF(
      strstrHTTPServer,
      strActionPage,
      "imageData.tif",
      OnHttpUploadSuccess,
      OnHttpUploadFailure
    );
}
//SaveToFile.aspx:
<%@ Page Language="C#" %>
<%
    try{
        String strImageName;
        HttpFileCollection files = HttpContext.Current.Request.Files;
        HttpPostedFile uploadfile = files["RemoteFile"];
        strImageName = uploadfile.FileName;
        uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName);
    }
    catch{
    }
%>
Usage notes If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v4.0+
HTTPUploadAllThroughPostAsPDF()
Uploads all of the images in the buffer to a specified HTTP server as a PDF file.
Syntax .HTTPUploadAllThroughPostAsPDF(strHTTPServer, actionPage, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the name of the HTTP server. For example: "www.dynamsoft.com", "localhost", "127.0.0.1".
string actionPage: the relative path for the action page on the server. The action page will receive and process the uploaded image stream.
string fileName: the file name to be saved on the server.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<onHttpUploadSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure.
Return value Boolean, only valid when used synchronously.
Example
function btnScan_onclick() 
{
    if (DWObject) {
        DWObject.SelectSource();
        DWObject.OpenSource();
        DWObject.IfDisableSourceAfterAcquire = true;
        DWObject.AcquireImage();
    }
}

// OnHttpUploadSuccess and OnHttpUploadFailure are callback functions.
function OnHttpUploadSuccess(httpResponse, newIndices, _arguments) {
    console.log('successful');
}
function OnHttpUploadFailure(errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert(errorString + httpResponse);
}

function btnUpload_onclick() 
{
    var strstrHTTPServer = location.hostname; //The name of the HTTP server. 
    var CurrentPathName = unescape(location.pathname);
    var CurrentPath = CurrentPathName.substring(0, 
    CurrentPathName.lastIndexOf("/") + 1);
    var strActionPage = CurrentPath + "SaveToFile.aspx";
    DWObject.IfSSL = false; // Set whether SSL is used
    DWObject.HTTPPort = location.port == "" ? 80 : location.port;

    
    // Upload all of the images in Dynamic Web TWAIN viewer 
    // to the HTTP server as a PDF file asynchronously
    DWObject.HTTPUploadAllThroughPostAsPDF(
      strstrHTTPServer, 
      strActionPage, 
      "imageData.pdf", 
      OnHttpUploadSuccess, 
      OnHttpUploadFailure
    );
}
//SaveToFile.aspx:
<%@ Page Language="C#" %>
<%
    try{
        String strImageName;
        HttpFileCollection files = HttpContext.Current.Request.Files;
        HttpPostedFile uploadfile = files["RemoteFile"];
        strImageName = uploadfile.FileName;
        uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName);
    }
    catch{
    }
%>
Usage notes If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v5.0+
HTTPUploadThroughPost()
Uploads the image of a specified index in the buffer to a specified HTTP server.
Syntax .HTTPUploadThroughPost(strHTTPServer, sImageIndex, actionPage, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the name of the HTTP server. For example: "www.dynamsoft.com", "localhost", "127.0.0.1".
number sImageIndex: the index of the image in the buffer. The index is 0-based.
string actionPage: the relative path for the action page on the server. The action page will receive and process the uploaded image stream.
string fileName: the file name to be saved on the server.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<onHttpUploadSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure.
Return value Boolean, only valid when used synchronously.
Example
function btnScan_onclick() 
{
    if (DWObject) {
        DWObject.SelectSource();
        DWObject.OpenSource();
        DWObject.IfDisableSourceAfterAcquire = true;
        DWObject.AcquireImage();
    }
}
// OnHttpUploadSuccess and OnHttpUploadFailure are callback functions.
function OnHttpUploadSuccess(httpResponse, newIndices, _arguments) {
    console.log('successful');
}
function OnHttpUploadFailure(errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert(errorString + httpResponse);
}

function btnUpload_onclick() 
{
    var strstrHTTPServer = location.hostname; //The name of the HTTP server. 
    var CurrentPathName = unescape(location.pathname);
    var CurrentPath = CurrentPathName.substring(0, 
    CurrentPathName.lastIndexOf("/") + 1);
    var strActionPage = CurrentPath + "SaveToFile.aspx";
    DWObject.IfSSL = false; // Set whether SSL is used
    DWObject.HTTPPort = location.port == "" ? 80 : location.port;

    
    // Upload the image of a specified index in 
    // Dynamic Web TWAIN viewer to the HTTP server asynchronously
    if (document.getElementById("JPEG").checked) {
        DWObject.HTTPUploadThroughPost(
          strstrHTTPServer, 
          DWObject.CurrentImageIndexInBuffer,
          strActionPage,
          "imageData.jpg",
          OnHttpUploadSuccess,
          OnHttpUploadFailure
        );
    }
    if (document.getElementById("PNG").checked) {
        DWObject.HTTPUploadThroughPost(
          strstrHTTPServer,
          DWObject.CurrentImageIndexInBuffer,
          strActionPage,
          "imageData.png",
          OnHttpUploadSuccess,
          OnHttpUploadFailure
        );
    }
    if (document.getElementById("BMP").checked) {
        DWObject.HTTPUploadThroughPost(
          strstrHTTPServer,
          DWObject.CurrentImageIndexInBuffer,
          strActionPage,
          "imageData.bmp",
          OnHttpUploadSuccess,
          OnHttpUploadFailure
        );
    }
}
//SaveToFile.aspx:
<%@ Page Language="C#" %>
<%
    try{
        String strImageName;
        HttpFileCollection files = HttpContext.Current.Request.Files;
        HttpPostedFile uploadfile = files["RemoteFile"];
        strImageName = uploadfile.FileName;
        uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName);
    }
    catch{
    }
%>
Usage notes Dynamic Web TWAIN processes the image format according to the extension of fileName.
If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v4.0+
HTTPUploadThroughPostAsMultiPagePDF()
Uploads the selected images in the buffer to a specified HTTP server as a PDF file.
Syntax .HTTPUploadThroughPostAsMultiPagePDF(strHTTPServer, actionPage, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the name of the HTTP server. For example: "www.dynamsoft.com", "localhost", "127.0.0.1".
string actionPage: the relative path for the action page on the server. The action page will receive and process the uploaded image stream.
string fileName: the file name to be saved on the server.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<onHttpUploadSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure.
Return value Boolean, only valid when used synchronously.
Example
function btnScan_onclick() 
{
    if (DWObject) {
        DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex);
        DWObject.OpenSource();
        DWObject.IfDisableSourceAfterAcquire = true;
        DWObject.AcquireImage();
    }
}

// OnHttpUploadSuccess and OnHttpUploadFailure are callback functions.
function OnHttpUploadSuccess(httpResponse, newIndices, _arguments) {
    console.log('successful');
}
function OnHttpUploadFailure(errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert(errorString + httpResponse);
}

function btnUpload_onclick() 
{
    var strstrHTTPServer = location.hostname; //The name of the HTTP server. 
    var CurrentPathName = unescape(location.pathname);
    var CurrentPath = CurrentPathName.substring(0, 
    CurrentPathName.lastIndexOf("/") + 1);
    var strActionPage = CurrentPath + "SaveToFile.aspx";
    DWObject.IfSSL = false; // Set whether SSL is used
    DWObject.HTTPPort = location.port == "" ? 80 : location.port;

    DWObject.SelectedImagesCount = 3;
    DWObject.SetSelectedImageIndex(0, 0); 
    // Set the 1st image as the first selected image.
    DWObject.SetSelectedImageIndex(1, 2); 
    // Set the 3rd image as the second selected image.
    DWObject.SetSelectedImageIndex(2, 4); 
    // Set the 5th image as the third selected image.
    DWObject.GetSelectedImagesSize(4); 
    // 4 - PDF format. Calculate the size of selected images in PDF format.

    
    // Upload the selected images to the server asynchronously
    DWObject.HTTPUploadThroughPostAsMultiPagePDF(
      strstrHTTPServer, 
      strActionPage, 
      "imageData.pdf", 
      OnHttpUploadSuccess, 
      OnHttpUploadFailure
    );
}
//SaveToFile.aspx:
<%@ Page Language="C#" %>
<%
    try{
        String strImageName;
        HttpFileCollection files = HttpContext.Current.Request.Files;
        HttpPostedFile uploadfile = files["RemoteFile"];
        strImageName = uploadfile.FileName;
        uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName);
    }
    catch{
    }
%>
Usage notes If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v6.0+
HTTPUploadThroughPostAsMultiPageTIFF()
Uploads selected images in the buffer to the HTTP server as a TIFF file.
Syntax .HTTPUploadThroughPostAsMultiPageTIFF(strHTTPServer, actionPage, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the name of the HTTP server. For example: "www.dynamsoft.com", "localhost", "127.0.0.1".
string actionPage: the relative path for the action page on the server. The action page will receive and process the uploaded image stream.
string fileName: the file name to be saved on the server.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<onHttpUploadSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure.
Return value Boolean, only valid when used synchronously.
Example
function btnScan_onclick() 
{
    if (DWObject) {
        DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex);
        DWObject.OpenSource();
        DWObject.IfDisableSourceAfterAcquire = true;
        DWObject.AcquireImage();
    }
}
// OnHttpUploadSuccess and OnHttpUploadFailure are callback functions.
function OnHttpUploadSuccess(httpResponse, newIndices, _arguments) {
    console.log('successful');
}
function OnHttpUploadFailure(errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert(errorString + httpResponse);
}

function btnUpload_onclick() 
{
    var strstrHTTPServer = location.hostname; //The name of the HTTP server. 
    var CurrentPathName = unescape(location.pathname);
    var CurrentPath = CurrentPathName.substring(0, 
    CurrentPathName.lastIndexOf("/") + 1);
    var strActionPage = CurrentPath + "SaveToFile.aspx";
    DWObject.IfSSL = false; // Set whether SSL is used
    DWObject.HTTPPort = location.port == "" ? 80 : location.port;

    DWObject.SelectedImagesCount = 3;
    DWObject.SetSelectedImageIndex(0, 0); 
    // Set the 1st image as the first selected image.
    DWObject.SetSelectedImageIndex(1, 2); 
    // Set the 3rd image as the second selected image.
    DWObject.SetSelectedImageIndex(2, 4); 
    // Set the 5th image as the third selected image.
    DWObject.GetSelectedImagesSize(2); 
    // 2 - TIFF format. Calculate the size of selected images in TIFF format.

    
    // Upload the selected images to the server asynchronously
    DWObject.HTTPUploadThroughPostAsMultiPageTIFF(
      strstrHTTPServer,
      strActionPage,
      "imageData.tiff",
      OnHttpUploadSuccess,
      OnHttpUploadFailure
    );
}
//SaveToFile.aspx:
<%@ Page Language="C#" %>
<%
    try{
        String strImageName;
        HttpFileCollection files = HttpContext.Current.Request.Files;
        HttpPostedFile uploadfile = files["RemoteFile"];
        strImageName = uploadfile.FileName;
        uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName);
    }
    catch{
    }
%>
Usage notes If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v6.0+
HTTPUploadThroughPostDirectly()
Upload any type of file to the server.
Syntax .HTTPUploadThroughPostDirectly(strHTTPServer, strLocalFile, actionPage, fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the name of the HTTP server. For example: "www.dynamsoft.com", "localhost", "127.0.0.1".
string strLocalFile: the path of the file to upload.
string actionPage: the relative path for the action page on the server. The action page will receive and process the uploaded file stream.
string fileName: the file name to be used when saving the file on the server.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<onHttpUploadSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure.
Return value Boolean, only valid when used synchronously.
Example
// OnHttpUploadSuccess and OnHttpUploadFailure are callback functions.
function OnHttpUploadSuccess(httpResponse) {
    console.log('successful');
}
function OnHttpUploadFailure(errorCode, errorString, httpResponse) {
    alert(errorString + httpResponse);
}

function btnUpload_onclick()
{
    var strstrHTTPServer = location.hostname; //The name of the HTTP server. 
    var CurrentPathName = unescape(location.pathname);
    var CurrentPath = CurrentPathName.substring(0, 
    CurrentPathName.lastIndexOf("/") + 1);
    var strActionPage = CurrentPath + "SaveToFile.aspx";
    DWObject.IfSSL = false; // Set whether SSL is used
    DWObject.HTTPPort = location.port == "" ? 80 : location.port;

    
    // Uploads a specific image in the buffer to 
    // the HTTP server in a specified image format asynchronously
    DWObject.HTTPUploadThroughPostDirectly(
      strstrHTTPServer,
      "D:\\DWT.jpg",
      strActionPage,
      "imageData.jpg",
      OnHttpUploadSuccess,
      OnHttpUploadFailure
    );
}
//SaveToFile.aspx:
<%@ Page Language="C#" %>
<%
    try{
        String strImageName;
        HttpFileCollection files = HttpContext.Current.Request.Files;
        HttpPostedFile uploadfile = files["RemoteFile"];
        strImageName = uploadfile.FileName;
        uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName);
    }
    catch{
    }
%>
Usage notes If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v7.0+
HTTPUploadThroughPostEx()
Uploads the image of a specified index in the buffer to the HTTP server in a specified image format.
Syntax .HTTPUploadThroughPostEx(strHTTPServer, sImageIndex, actionPage, fileName, imageType, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string strHTTPServer: the name of the HTTP server. For example: "www.dynamsoft.com", "localhost", "127.0.0.1".
number sImageIndex: the index of the image in the buffer. The index is 0-based.
string actionPage: the relative path for the action page on the server. The action page will receive and process the uploaded image stream.
string fileName: the file name to be saved on the server.
EnumDWT_ImageType imageType: the format of the image.
Type Numeric Value
IT_BMP 0
IT_JPG 1
IT_TIF 2
IT_PNG 3
IT_PDF 4
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
<onHttpUploadSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be uploaded.
Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure.
Return value Boolean, only valid when used synchronously.
Example
function btnScan_onclick() 
{
    if (DWObject) {
        DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex);
        DWObject.OpenSource();
        DWObject.IfDisableSourceAfterAcquire = true;
        DWObject.AcquireImage();
    }
}

// OnHttpUploadSuccess and OnHttpUploadFailure are callback functions.
function OnHttpUploadSuccess(httpResponse, newIndices, _arguments) {
    console.log('successful');
}
function OnHttpUploadFailure(errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert(errorString + httpResponse);
}

function btnUpload_onclick() 
{
    var strstrHTTPServer = location.hostname; //The name of the HTTP server. 
    var CurrentPathName = unescape(location.pathname);
    var CurrentPath = CurrentPathName.substring(0, 
    CurrentPathName.lastIndexOf("/") + 1);
    var strActionPage = CurrentPath + "SaveToFile.aspx";
    DWObject.IfSSL = false; 
    // Set whether SSL is used
    DWObject.HTTPPort = location.port == "" ? 80 : location.port;

    
    // Uploads a specific image in the buffer to the HTTP
    // server in a specified image format asynchronously
    DWObject.HTTPUploadThroughPostEx(
      strstrHTTPServer, 
      DWObject.CurrentImageIndexInBuffer, 
      strActionPage, "imageData.jpg", 
      EnumDWT_ImageType.IT_JPG, 
      OnHttpUploadSuccess, 
      OnHttpUploadFailure
    );
}
//SaveToFile.aspx:
<%@ Page Language="C#" %>
<%
    try{
        String strImageName;
        HttpFileCollection files = HttpContext.Current.Request.Files;
        HttpPostedFile uploadfile = files["RemoteFile"];
        strImageName = uploadfile.FileName;
        uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName);
    }
    catch{
    }
%>
Usage notes If you want to use this method to upload / download files through HTTPS, please don't forget to set IfSSL to true and set the correct HTTPPort.
Availability v5.0+
SetHTTPFormField()
Sets up a field in the web form which will be sent to the server once an upload is initiated. You can set multiple fields by calling this method mutliple times.
Syntax .SetHTTPFormField(fieldName, fieldValue);
.SetHTTPFormField(fieldName, blobValue, optional fileName);
Parameters string fieldName: the name of the field which can later be used on the server to retrieve the field value.
string fieldValue: the field value.
string fieldName: the name of the field which can later be used on the server to retrieve the blob.
Blob blobValue: the binary data to be uploaded.
string fileName: the name to be used when saving the binary on the server.
Return value boolean
Example
DWObject.ClearAllHTTPFormField();
DWObject.SetHTTPFormField("PDFFileName", "test.pdf");
//Get action page path
var CurrentPathName = unescape(location.pathname); 
var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
var strActionPage = CurrentPath + "SaveToFile.aspx";
DWObject.HTTPUploadAllThroughPostAsMultiPageTIFF(
  "www.dynamsoft.com",
  strActionPage,
  "test.tiff"
);
//C# Action Page Part:
System.Web.HttpContext.Current.Request.Form["PDFFileName"];
Usage notes It was improved to be able to set Blobs in HTTP Forms aside from strings from v13.1.
Availability v5.0+
SetUploadSegment()
Specifies when an upload should be segmented and the size of the segments.
Syntax .SetUploadSegment(segementUploadThreshold, moduleSize);
Parameters number segementUploadThreshold: the threshold (in MB) over which segmented upload will be invoked.
number moduleSize: the size of each segment (in KB).
Return value boolean
Availability v12.1+
SetHTTPHeader()
Adds a header to an http(s) post request. This header will be cleared every time a HTTPUpload/HTTPDownload request is done.
Syntax .SetHTTPHeader(HeaderName, HeaderValue);
Parameters string HeaderName: the name of the header which can later be used on the server to retrieve the header value.
string HeaderValue: the header value.
Return value boolean
Example
DWObject.SetHTTPHeader('dwt_CustomHeader','dynamsoft');
DWObject.HTTPUpload('www.dynamsoft.com/SaveToFile.aspx', 
[0,1],  EnumDWT_ImageType.IT_PDF, EnumDWT_UploadDataFormat.Binary, 
'test.pdf', OnHttpUploadSuccess, OnHttpUploadFailure);
function OnHttpUploadSuccess (httpResponse, newIndices, _arguments) {
    console.log("HTTPResponseString: " + httpResponse);
}

function OnHttpUploadFailure (errorCode, errorString, httpResponse, newIndices, _arguments) {
    alert("ErrorCode: " + errorCode+ "ErrorString: " + 
    errorString + "HTTPResponseString: " + httpResponse);
}
Usage notes This method is valid only in the HTML5 Edition.
Availability v12.0+

Properties

FTPPassword
Returns or sets the password used to log into the FTP server.
Type string
Accessors Get Set
Usage notes If you are logging into a FTP server as "anonymous", then you don't need to set FTPUserName or FTPUserPassword.
Availability v5.2+
FTPPort
Returns or sets the port number of the FTP server to be used for uploading/downloading.
Type number
Accessors Get Set
Usage notes The default FTP port number is 21.
Availability v5.2+
FTPUserName
Returns or sets the username used to log into a FTP server.
Type string
Accessors Get Set
Usage notes If you are logging into a FTP server as "anonymous", then you don't need to set FTPUserName or FTPUserPassword.
Availability v5.2+
HttpFieldNameOfUploadedImage
Returns or sets the field name of the uploaded image when uploading through POST.
Type string
Accessors Get Set
Usage notes The default value is "RemoteFile".
Availability v6.0+
HTTPPort
Returns or sets the port number to be used for uploading via HTTP.
Type number
Accessors Get Set
Usage notes The default HTTP port number is 80. This property is typically used with (IfSSL)[#IfSSL].
Availability v4.2.1+
HTTPPostResponseString
Returns the response string from the HTTP server if an error occurred after calling one of the HTTPUploadThroughPost*** methods.
Type string
Accessors Get
Usage notes This is a read-only property.
Availability v3.0.3+
IfPASVMode
Returns or sets whether FTP passive mode is enabled.
Type boolean
Accessors Get Set
Usage notes The default value is true.
When the value of the property is true, FTP passive mode is enabled.
When the value of the property is set to false, FTP active mode is enabled.
Availability v6.0+
IfShowCancelDialogWhenImageTransfer
Returns or sets whether to show the cancel dialog when uploading images to server. The default value is true.
Type boolean
Accessors Get Set
Usage notes

In the HTML5 Edition, this property only works with asynchronous uploading.
The IfShowProgressBar property works for any image encoding/decoding related methods. For example: LoadImage,LoadImageEx, etc.

Property Value HTML5 Edition Non-HTML5 Editions (ActiveX / Plugin)
IfShowCancelDialogWhenImageTransfer true Upload/Download:
The progress bar will appear.
Upload/Download:
The progress bar will appear.
false Upload/Download:
The progress bar will not appear.
Upload/Download:
The progress bar will not appear.
IfShowProgressBar true Save/Load:
The progress bar will appear.
Save/Load:
The progress bar will appear.

Upload/Download (Encoding/Decoding):
The progress bar will appear.
false Save/Load:
The progress bar will not appear.
Save/Load:
The progress bar will not appear.

Upload/Download (Encoding/Decoding):
The progress bar will not appear.
Availability v5.2+
IfSSL
Returns or sets whether SSL is used when uploading or downloading images.
Type number
Accessors Get Set
Usage notes The default value is false.
This property is typically used with HTTPPort. If IfSSL is set to true, make sure HTTPPort is set to a secure port like 443.
Availability v5.2+
MaxUploadImageSize
Returns or sets the size limit for uploading images.
Type number
Accessors Get Set
Usage notes The default value is -1 which indicates there is no limit over the upload size. The value should be equal or smaller than 2147483647 which essentially means 2 GB. The unit is 'Byte'.
Availability v5.2+

Events

OnInternetTransferPercentage
This event is triggered during image uploading or downloading.
Syntax .RegisterEvent('OnInternetTransferPercentage',function(sPercentage){...});
Arguments
  • number sPercentage: the percentage that has been uploaded or downloaded.
Example
DWObject.RegisterEvent('OnInternetTransferPercentage', function(sPercentage) {
    console.log(sPercentage);
});
Usage notes
Availability v5.0+

results matching ""

    No results matching ""

    results matching ""

      No results matching ""