upload multiple files with ajaxFileUpload with dif

2019-03-04 05:39发布

I am trying to upload multiple files in the same form. Multiple files should be in different fields. I used ajaxfileuploader for single file and receive it using MultipartHttpServletRequest. And it was successful.

I used

 $.ajaxFileUpload
(
{
        url: 'uploadfile',
        secureuri: false,
        fileElementId:'setup',
        dataType: 'text',
        data: { id: id },
        success: function (data, status) {

            if (status == 'success') {

                return;
            } else {
            }

        },
        error: function (data, status, e) {
            return alert('Error ! Failed to upload file!');
        }
    }
)

But my problem is I have many files to be uploaded by single request. For example setup1,setup2,setup3 (different ids). How to give multiple ids on ajaxFileUpload? Your kind reply is appreciated

Thank you

2条回答
该账号已被封号
2楼-- · 2019-03-04 06:20

You can wrap that code in a function and call it multiple times since the plugin doesn't support multiple elements in once request

var uploadFile = function (elementID) {
    $.ajaxFileUpload({
        url: 'uploadfile',
        secureuri: false,
        fileElementId: elementID,
        dataType: 'text',
        data: {
            id: id
        },
        success: function (data, status) {
            if (status == 'success') {
                return;
            } else {}
        },
        error: function (data, status, e) {
            return alert('Error ! Failed to upload file!');
        }
    });
};

Then use it this way

uploadFile('file1');
uploadFile('file12');
查看更多
该账号已被封号
3楼-- · 2019-03-04 06:30

Consider to use this JQuery plugin for multiUpload. http://hayageek.com/docs/jquery-upload-file.php

查看更多
登录 后发表回答