Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit a0cc717

Browse files
Allow configurable file param name
1 parent 42f4dd9 commit a0cc717

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/uploader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function uiUploader($log) {
4141
}
4242
if (self.files[i].active)
4343
continue;
44-
ajaxUpload(self.files[i], self.options.url, self.options.data, headers);
44+
ajaxUpload(self.files[i], self.options.url, self.options.data, self.options.paramName, headers);
4545
}
4646
}
4747

@@ -68,9 +68,10 @@ function uiUploader($log) {
6868
return (bytes / Math.pow(1024, i)).toFixed(i ? 1 : 0) + ' ' + sizes[isNaN(bytes) ? 0 : i + 1];
6969
}
7070

71-
function ajaxUpload(file, url, data, headers) {
72-
var xhr, formData, prop, key = 'file';
71+
function ajaxUpload(file, url, data, key, headers) {
72+
var xhr, formData, prop;
7373
data = data || {};
74+
key = key || 'file';
7475

7576
self.activeUploads += 1;
7677
file.active = true;

test/uploaderSpec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,32 @@ describe('uiUploader', function() {
5353
expect(uiUploader.files).toEqual(files);
5454
});
5555
});
56+
57+
describe('#startUpload', function() {
58+
var formData;
59+
var file;
60+
61+
beforeEach(function() {
62+
file = new File([''], 'testFile');
63+
formData = {
64+
append: jasmine.createSpy()
65+
};
66+
67+
uiUploader.addFiles([file]);
68+
69+
spyOn(window, 'FormData').and.returnValue(formData);
70+
});
71+
72+
describe('with a specified paramName', function() {
73+
beforeEach(function() {
74+
uiUploader.startUpload({
75+
paramName: 'test'
76+
});
77+
});
78+
79+
it('sets the paramName when appending the formdata', function() {
80+
expect(formData.append).toHaveBeenCalledWith('test', file, 'testFile');
81+
});
82+
});
83+
});
5684
});

0 commit comments

Comments
 (0)