1

I am using angularjs file uploader given at "https://github.com/nervgh/angular-file-upload", so my js code look like this:

var uploader = $scope.uploader = new FileUploader({
  url: 'uploadUrl1.php' 
 });

 uploader.filters.push({
        name: 'customFilter',
        fn: function(item /*{File|FileLikeObject}*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
    });

and I used it like this in html :

 <input type="file" id="fileInput" nv-file-select="" class="upload" uploader="uploader">

How can I define another uploader say uploader2 in order to post data to different url say uploadUrl2.php.

1 Answer 1

1

You could create two separate instances of FileUploader and give each one a different URL. For example:

JavaScript

// Define our URLs. Each URL will have it's own instance of FileUploader
var urls = ['uploadUrl1.php', 'uploadUrl2.php'];

// Define our shared filter
var filterObj = {
    name: 'customFilter',
    fn: function(item /*{File|FileLikeObject}*/, options) {
        var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
        return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
    }
};

// Create a new instance of FileUploader with each URL and
// give each instance the filter too
var uploaders = $scope.uploaders = urls.map(function(url) {
    var uploader = new FileUploader({url: url});
    uploader.filters.push(filterObj);
    return uploader;
});

Template

<input type="file" id="fileInput" nv-file-select="" class="upload" uploader="uploaders[0]" />
<input type="file" id="fileInput" nv-file-select="" class="upload" uploader="uploaders[1]" />
Sign up to request clarification or add additional context in comments.

2 Comments

so to retrieve any info regarding uploader like queue length, How should I call uploader.queue.length or uploader[0].queue.length?
You would use uploaders[0].queue.length as uploaders is an array of FileUploader instances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.