How to cancel the download of files and automatically delete the recording if the download failed in angular meteor and collectionfs?

Html:

<div ngf-select ngf-keep="true" ng-model="vm.photos" ngf-accept="'image/*'" ngf-pattern="'image/*'" ngf-multiple="true"> Select </div> <button ng-click="vm.uploadPhotos()">Upload</button> 

JS Client:

 vm.uploadPhotos = function() { _.forEach(vm.photos, function(photo) { PhotoCol.insert(photo); }); }; 

JS Server:

 PhotoCol = new FS.Collection('propertyPhoto', { stores: [ new FS.Store.FileSystem('original') ], filter: { allow: { contentTypes: ['image/*'] } } }); PhotoCol.allow({ insert: function() { return true; }, update: function() { return true; }, remove: function() { return true; }, download: function() { return true; } }); 

When the download starts, I need a way to cancel one or all of the download processes. And CollectionFS writes to the database until the download is complete, so if for some reason the user has stopped the browser before the download process is complete, I will have an entry for the photo without the downloaded file. Here I need to catch this error in order to delete a record from the database. Any ideas?

+5
source share

Source: https://habr.com/ru/post/1241324/


All Articles