Comments (7)
Oups, увидел что у меня не актуальная версия библиотеки. В актуальной как раз это исправлено.
from angular-file-upload.
Мм. Поспешил, теперь isComplete фактически оставил проблему. Не могу понять, каким же всё таки нужно пойти путём ?
from angular-file-upload.
Подскажите пожалуйста как загружать файлы повторно, если они не загрузились с первого раза?
item.upload();
// or
uploader.uploadItem([item|indexOfItem]);
Перед тем как загружать файлы, делается проверка:
Ситуация такая: допустим в настройках загрузчика стоит "автозагрузка" uploader.autoUpload = true
. Если загрузка файла вернет ошибку, то загрузчик уйдет в бесконечный цикл:
- выбрать не загруженные файлы
- загрузить их
- если загрузка завершилась неудачей, GoTo 1
Для решения этой проблемы был введен флагitem.isComplete = true;
файл был загружен, причем успешно или не успешно не важно.
Чтобы решить ваш казус, придется написать функцию получения файлов, загруженных с ошибкой:
uploader.getFilesWithUploadError = function() {
return this.queue.filter(function (item) {
return !item.isUploaded;
});
};
var arr = uploader.getFilesWithUploadError();
arr.length && arr.forEach(function(item) {
item.upload();
});
не проверял, но должно работать. Если возникнут проблемы, пишите.
Конечно, надо либо переименовать getNotUploadedItems
, либо подумать, о том, как сделать получение незагруженных файлов более удобным...
from angular-file-upload.
Я решил пойти немного другим путём. Теперь всегда вызывается функция uploader.uploadAll()
, и ожидается событие completeall
Но и здесь я столкнулся с вещью, которую впринципе решил, но суть вот в чем:
Ситуация: при submit'e формы вызывается uploadAll()
, после того как файлы загружены - необходимо сделать некоторые действия. И если эти действия завершаются неудачей, далее юзер изменяет данные на валидные (например), и снова сабмитится форма. Опять вызывается метод uploadAll
, НО! событие completeall в данном случае не выбрасывается, потому что все файлы в предыдущем запросе загрузились успешно.
Я добавил в метод uploadall строку
uploadAll: function () {
var items = this.getNotUploadedItems().filter(function(item) {
return !item.isUploading;
});
items.forEach(function(item) {
item.index = item.index || this._nextIndex++;
item.isReady = true;
}, this);
items.length && this.uploadItem(items[ 0 ]);
// added
items.length || this.trigger('completeall', this.queue);
return this;
}
которая бросает событие completeall даже в том случае, если в очереди на загрузке не осталось ничего.
Может быть я архитектурно не верно мыслю?
from angular-file-upload.
Может быть я архитектурно не верно мыслю?
На первый взгляд, да. Чем не устроил мой вариант?
from angular-file-upload.
Ваш вариант полностью устроил, я лишь привел решение, к которому пришел не дождавшись вашей помощи :)
from angular-file-upload.
Ваш вариант полностью устроил, я лишь привел решение, к которому пришел не дождавшись вашей помощи
Кстати, я там ошибся ^__^ Правильней так будет:
uploader.getFilesWithUploadError = function() {
return this.queue.filter(function (item) {
return !item.isUploaded && item.isComplete;
});
};
Читается как: если файл не загружен, но отправлялся на сервер / пытался загрузиться.
Хотя, наверное, проще будет флаг item.isError
добавить.
from angular-file-upload.
Related Issues (20)
- angular is not defined HOT 1
- Unable to upload file from Angular 7/8 and backend Spring security project HOT 2
- Callback when no file was valid HOT 3
- timeout HOT 1
- Calling a upload function on button click instead of image upload. HOT 1
- Rename file upload "choose file"
- onAfterAddingFile callback not firing without code change HOT 1
- Rename file according to input name HOT 2
- Bug in IE setting xhr.timeout before xhr.open() in version 2.6.0 HOT 4
- ngf-thumbnail is breaking image orientation HOT 2
- Question: clearing the input.value property to circumvent a bug in chrome
- Drag and Drop not working in Chrome occasionally HOT 2
- "Unsupported Media Type", message: "Content type 'application/octet-stream' not supported"
- Get real path File before upload
- angular1 single item does not add formdata HOT 1
- When I send a file single file use sample code, ,i got a page reload
- Sabuj gazi
- Adding an image captured via camera HOT 1
- How do you post the file data to ASP.Net HOT 1
- How to Costume Header HTTP
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-file-upload.