Skip to content

Commit 47e42c0

Browse files
committed
Fix #1136: Allow proper retry of error uploads based on retryErrorUploads setting
1 parent 49feb4a commit 47e42c0

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

CHANGE.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change Log: `bootstrap-fileinput`
55

66
**Date:** 18-Apr-2019
77

8+
- (enh #1136): Allow proper retry of error uploads based on `retryErrorUploads` setting.
89
- Better management of console log messages.
910
- (bug #1391): Correct resumable upload progress update behavior when `showPreview` is `false`.
1011
- (bug #1390): Correct remove button display validation set via `fileActionSettings`.

examples/index.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ <h1>Bootstrap File Input Examples
4040
<button type="reset" class="btn btn-outline-secondary">Reset</button>
4141
</form>
4242
<hr>
43+
<h5>Preupload Validation</h5>
44+
<input id="file-0" name="file-0" type="file">
45+
<br>
46+
<textarea id="description" rows=3" class="form-control" placeholder="Enter description for the files selected..."></textarea>
47+
<br>
4348
<form enctype="multipart/form-data">
4449
<label for="file-0b">Test invalid input type</label>
4550
<div class="file-loading">
@@ -142,7 +147,9 @@ <h4>Multi Language Inputs</h4>
142147
});
143148
$("#file-0").fileinput({
144149
theme: 'fas',
145-
'allowedFileExtensions': ['jpg', 'png', 'gif']
150+
uploadUrl: '#'
151+
}).on('filepreupload', function(event, data, previewId, index) {
152+
alert('The description entered is:\n\n' + ($('#description').val() || ' NULL'));
146153
});
147154
$("#file-1").fileinput({
148155
theme: 'fas',

js/fileinput.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@
771771
self.fileManager = {
772772
stack: {},
773773
processed: [],
774+
errors: [],
774775
loadedImages: {},
775776
totalImages: 0,
776777
totalFiles: null,
@@ -904,6 +905,7 @@
904905
fm.totalSize = null;
905906
fm.uploadedSize = 0;
906907
fm.stack = {};
908+
fm.errors = [];
907909
fm.processed = [];
908910
fm.stats = {};
909911
fm.clearImages();
@@ -2042,9 +2044,9 @@
20422044
self._raise('filefoldererror', [folders, msg]);
20432045
},
20442046
_showUploadError: function (msg, params, event) {
2045-
var self = this, $error = self.$errorContainer, ev = event || 'fileuploaderror', fId = params.fileId || '',
2046-
e = params && params.id ?
2047-
'<li data-thumb-id="' + params.id + '" data-file-id="' + fId + '">' + msg + '</li>' : '<li>' + msg + '</li>';
2047+
var self = this, $error = self.$errorContainer, ev = event || 'fileuploaderror',
2048+
fId = params && params.fileId || '', e = params && params.id ?
2049+
'<li data-thumb-id="' + params.id + '" data-file-id="' + fId + '">' + msg + '</li>' : '<li>' + msg + '</li>';
20482050
if ($error.find('ul').length === 0) {
20492051
self._addError('<ul>' + e + '</ul>');
20502052
} else {
@@ -2755,7 +2757,7 @@
27552757
}
27562758
if (self.isAjaxUpload) {
27572759
if (self.fileManager.count() > 0) {
2758-
files = self.fileManager.stack;
2760+
files = $.extend(true, {}, self.fileManager.stack);
27592761
self.fileManager.clear();
27602762
self._clearFileInput();
27612763
} else {
@@ -3178,10 +3180,12 @@
31783180
}
31793181
updateUploadLog = function () {
31803182
if (!uploadFailed) {
3181-
self.fileManager.removeFile(id);
3183+
fm.removeFile(id);
3184+
} else {
3185+
fm.errors.push(id);
31823186
}
3183-
self.fileManager.setProcessed(id);
3184-
if (self.fileManager.isProcessed()) {
3187+
fm.setProcessed(id);
3188+
if (fm.isProcessed()) {
31853189
self.fileBatchCompleted = true;
31863190
}
31873191
};
@@ -3191,7 +3195,7 @@
31913195
return;
31923196
}
31933197
setTimeout(function () {
3194-
var triggerReset = self.fileManager.count() === 0;
3198+
var triggerReset = fm.count() === 0, errCount = fm.errors.length;
31953199
self._updateInitialPreview();
31963200
self.unlock(triggerReset);
31973201
if (triggerReset) {
@@ -3202,8 +3206,10 @@
32023206
$h.addCss($initThumbs, $h.SORT_CSS);
32033207
self._initSortable();
32043208
}
3205-
self._raise('filebatchuploadcomplete', [self.fileManager.stack, self._getExtraData()]);
3206-
self.fileManager.clear();
3209+
self._raise('filebatchuploadcomplete', [fm.stack, self._getExtraData()]);
3210+
if (!self.retryErrorUploads || errCount === 0) {
3211+
fm.clear();
3212+
}
32073213
self._setProgress(101);
32083214
self.ajaxAborted = false;
32093215
}, self.processDelay);
@@ -3226,6 +3232,9 @@
32263232
if (!isBatch) {
32273233
self.lock();
32283234
}
3235+
if (fm.errors.indexOf(id) !== -1) {
3236+
delete fm.errors[id];
3237+
}
32293238
self._raise('filepreupload', [outData, previewId, i]);
32303239
$.extend(true, params, outData);
32313240
if (self._abort(params)) {

js/fileinput.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)