Dev Center
Table of contents

Thanks for Downloading Dynamic Web TWAIN 30-Day Trial!

Your download will start shortly. If your download does not begin, click here to retry.

Document Saving

How to upload multiple files at a time?

Scenario:

After scanning multiple files, you might want to upload them one by one as individual images. Before version 13.1, you have to call the upload method(s) multiple times. From version 13.1+, you can do this in one go.

Solution:

You can use the methods ConvertToBlob and HTTPUpload to achieve this.

Steps:

  1. In JS, write code similar to the following:
    function UploadAsJPG() {
     var count = 0;
     DWObject.ClearAllHTTPFormField();
     DWObject.SetHTTPFormField("UploadedImagesCount",DWObject.HowManyImagesInBuffer);
    
     function asyncFailureFunc(errorCode, errorString) {
         alert("ErrorCode: " + errorCode + "\r" + "ErrorString:" + errorString);
     };
    
     var onEmptyResponse = function () {
         console.log("Uploaded Successfully");
     };
    
     var onServerReturnedSomething = function (ecode,estring,resp) {
         console(resp);
     }
    
     var convertImage = function (_index) {
         DWObject.ConvertToBlob(
             [_index], 
             Dynamsoft.DWT.EnumDWT_ImageType.IT_JPG,
             function (result) {
                 DWObject.SetHTTPFormField('image_' + _index, result, 'JPG_image_' + _index);
                 count++;
                 if (count < DWObject.HowManyImagesInBuffer) {
                     convertImage(count);
                 } else {
                     DWObject.HTTPUpload("http://localhost:90/saveUploadedJPG.aspx", onEmptyResponse, onServerReturnedSomething);// Please replace the URL with yours.
                 }
             }, 
             asyncFailureFunc
         );
     };
    
     convertImage(0);
    }
    
  2. On the server, add an action page to process the uploaded data, take c# as an example,
    <%@ Page Language="C#" %>
    <%
     try
     {
         String strImageName;
         String strInfo = HttpContext.Current.Request["UploadedImagesCount"];
         short uploadedImagesCount = Convert.ToInt16(strInfo);
         HttpFileCollection files = HttpContext.Current.Request.Files;
         for (short i = 0; i < uploadedImagesCount; i++)
         {
             HttpPostedFile uploadfile = files["image_" + i.ToString()];
             strImageName = uploadfile.FileName;
        
             uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName + ".jpg");
         }
     }
     catch
     {
     }
    %>
    

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest Version (18.4)
    • Version 18.3
    • Version 18.1
    • Version 18.0
    • Version 17.3
    • Version 17.2.1
    • Version 17.1.1
    • Version 17.0
    • Version 16.2
    • Version 16.1.1
    Change +