我看到Github的問題說,這是目前不支持,但似乎相對簡單的分叉這個項目,並將其彎曲到您的需求。所有的fnError =
的你會發現在Cmd + F
搜索裏面fileinput.js
是你需要看的地方。
例如採用這裏:https://github.com/kartik-v/bootstrap-fileinput/blob/d5ed3ee989edbd5d67b8cf4bdadc9f3c18609965/js/fileinput.js#L1897
這是批處理文件上傳,目前看起來是這樣的:
fnError = function (jqXHR, textStatus, errorThrown) {
var outData = self._getOutData(jqXHR), errMsg = self._parseError(jqXHR, errorThrown);
self._showUploadError(errMsg, outData, 'filebatchuploaderror');
self.uploadFileCount = total - 1;
if (!self.showPreview) {
return;
}
self._getThumbs().each(function() {
var $thumb = $(this), key = $thumb.attr('data-fileindex');
$thumb.removeClass('file-uploading');
if (self.filestack[key] !== undefined) {
self._setPreviewError($thumb);
}
});
self._getThumbs().removeClass('file-uploading');
self._getThumbs(' .kv-file-upload').removeAttr('disabled');
self._getThumbs(' .kv-file-delete').removeAttr('disabled');
};
我會嘗試修改該到:
fnError = function (jqXHR, textStatus, errorThrown) {
if (!myError.equals(textStatus)) { // A service-like impl. injection would be sexier
var outData = self._getOutData(jqXHR), errMsg = self._parseError(jqXHR, errorThrown);
self._showUploadError(errMsg, outData, 'filebatchuploaderror');
self.uploadFileCount = total - 1;
if (!self.showPreview) {
return;
}
self._getThumbs().each(function() {
var $thumb = $(this), key = $thumb.attr('data-fileindex');
$thumb.removeClass('file-uploading');
if (self.filestack[key] !== undefined) {
self._setPreviewError($thumb);
}
});
self._getThumbs().removeClass('file-uploading');
self._getThumbs(' .kv-file-upload').removeAttr('disabled');
self._getThumbs(' .kv-file-delete').removeAttr('disabled');
} else {
self._ajaxSubmit(fnBefore, fnSuccess, fnComplete, function() {
// TODO: Second time failure - handle recursively or differently? :-)
);
}
};
希望這可以幫助!
你能否在plunkr中提供演示,因爲現在插件網站正在關閉 –
@PareshGami我現在不能創建一個片段,但基本上它正是它應該做的。但是,我也問過Kartik,他回答說目前這是不可能的:https://github.com/kartik-v/bootstrap-fileinput/issues/637 –
@FlorianMüller對你來說還沒有解決?我認爲https://github.com/kartik-v/bootstrap-fileinput/blob/master/js/fileinput.js#L1534是你應該能夠很容易地編寫你的重試邏輯的地方:-) – Angad