Resources Base
Table of contents

Development

Can I upload multiple images as separate files in one go?

By design, the method HTTPUpload() only contains one file. But as it essentially sends an HTTP form to the server, you can attach multiple files in that form using the methods ConvertToBlob() and SetHTTPFormField() .

Check out the following snippet on how it is done. NOTE that the method HTTPUpload() only has 3 parameters as it doesn’t need to specify a file anymore.

/**
 * Upload the images specified by their indices in the specified file type as separate files.
 * @param indices Specify the images
 * @param type Specify the file type
 */
function uploadSeparateFiles(indices, type) {
    var protocol = Dynamsoft.Lib.detect.ssl ? "https://" : "http://",
        port = window.location.port === "" ? 80 : window.location.port,
        actionPage = "/upload.aspx";
    // path to the server-side script
    var url = protocol + window.location.hostname + ":" + port + actionPage;
    if (DWObject) {
        var done = 0,
            count = indices.length;
        var toBlob = function(index) {
            var fieldName = "SampleFile_" + index;
            var fileName = fieldName + getExtension(type);
            DWObject.ConvertToBlob(
                [index],
                type,
                function(result, _indices, type) {
                    DWObject.SetHTTPFormField(
                        fieldName,
                        result,
                        fileName
                    );
                    done++;
                    if (done === count) {
                        DWObject.HTTPUpload(
                            url,
                            function() {
                                console.log('Success');
                            },
                            function(errCode, errString, responseStr) {
                                console.log(errString);
                            }
                        );
                    } else {
                        toBlob(indices[done]);
                    }
                },
                function(errorCode, errorString) {
                    console.log(errorString);
                }
            );
        }
        toBlob(indices[done]);
    }
}

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest Version
    • Version 17.0
    • Version 16.2
    • Version 16.1.1
    Change +
    © 2003–2021 Dynamsoft. All rights reserved.
    Privacy Statement / Site Map / Home / Purchase / Support