danielm / uploader

A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
https://danielmg.org/demo/java-script/uploader
MIT License
1.17k stars 384 forks source link

How to set different urls for multiple uploaders on the same page #117

Closed S-ami closed 3 years ago

S-ami commented 3 years ago

Hello, so I have 3 elements with class eg. 'my-uploader' on the same page, each one of them has it's own data-url where the file should be uploaded.

I would need something like this:

$(function () {
    $('.my-uploader').dmUploader({
        maxFileSize: 15000000,
        url: $(this).data('url'), // get data of this concrete my-uploader element
        onInit: function () {
            ....
        }
   });
});

Is there any way to do this or do I have to setup multiple uploaders for every one of the elements and bind them by id?

EDIT:

The solution was to loop through the $('my-uploader') class and init the uploader for each one of them and then I could easily call $(this).data('url'). I am sorry for posting this but I struggled a lot before realizing this, I can't delete this now

musaev-haybulla commented 3 years ago

Can you write an example? I can't figure out what needs to be done

S-ami commented 3 years ago

Can you write an example? I can't figure out what needs to be done

Hello, this was quite a while, so I will try my best from what I remember:

$(function () {
    $('.my-uploader').each({
        $(this).dmUploader({
            maxFileSize: 15000000,
            url: $(this).data('url'), // get data of this concrete my-uploader element
            onInit: function () {
                ....
            }
        })
   });
});

Basically just each loop through class that your uploaders have and then initialize the uploader inside the each loop using $(this)