Beispiel #1
0
 public Task DeleteFile(ObjectId id)
 {
     return(Task.Run(() =>
     {
         gridFS.Delete(id);
     }));
 }
Beispiel #2
0
        public void DeleteFile(string path)
        {
            var files      = _bucket.Find(Builders <GridFSFileInfo> .Filter.Empty).ToList();
            var fileResult = files.FirstOrDefault(x => x.Filename == path);

            if (fileResult != null)
            {
                _bucket.Delete(fileResult.Id);
            }
        }
Beispiel #3
0
        public void Delete(Uri uri)
        {
            var id = GetId(uri);

            if (id.IsNotEmpty())
            {
                _fileBucket.Delete(id);
            }
        }
        /// <summary>
        /// Use the Delete or DeleteAsync methods to delete a single file identified by its Id.
        /// </summary>
        public void DeletingFiles(ObjectId id)
        {
            //For example, to find the newest revision of the file named “securityvideo” uploaded in January 2015:

            IGridFSBucket bucket = GetGridFSBucket();

            bucket.Delete(id);
            //await bucket.DeleteAsync(id);
        }
Beispiel #5
0
        public void UploadFileTopic(IFormFile file, string id)
        {
            try
            {
                var topicTemp = GetTopic(id);
                if (topicTemp.IconUrl != null && topicTemp.IconType != null)
                {
                    bucket.Delete(ObjectId.Parse(topicTemp.IconUrl));
                }
            }
            catch (MongoDB.Driver.GridFS.GridFSFileNotFoundException) { }

            using (var stream = file.OpenReadStream())
            {
                var idFile    = bucket.UploadFromStream(file.FileName, stream).ToString();
                var topicTemp = GetTopic(id);
                topicTemp.IconUrl  = idFile;
                topicTemp.IconType = file.ContentType;
                _topics.ReplaceOne(topic => topic.Id == id, topicTemp);
            }
        }
Beispiel #6
0
        public OperationResult Execute(CancellationToken cancellationToken)
        {
            try
            {
                _bucket.Delete(_id, cancellationToken);

                return(OperationResult.FromResult(null));
            }
            catch (Exception exception)
            {
                return(OperationResult.FromException(exception));
            }
        }
        public void DeletingAllFiles(string filename)
        {
            IGridFSBucket bucket = GetGridFSBucket();

            var filter = Builders <GridFSFileInfo> .Filter.Eq(x => x.Filename, filename);

            var filesCursor = bucket.Find(filter);
            var files       = filesCursor.ToList();

            foreach (var file in files)
            {
                bucket.Delete(file.Id);
            }
        }
        private void DeleteMongoFile(IGridFSBucket bucket, string fileId)
        {
            Logger.Debug($"Deleting MongoDb Channel Data file: {fileId}");

            var filter = Builders <GridFSFileInfo> .Filter.Eq(fi => fi.Metadata[FileQueryField], fileId);

            var mongoFile = bucket.Find(filter).FirstOrDefault();

            if (mongoFile == null)
            {
                return;
            }

            bucket.Delete(mongoFile.Id);
        }
Beispiel #9
0
        private ObjectId UpdateEmployeePicture(Guid employeeId, byte[] picture)
        {
            FilterDefinition <GridFSFileInfo> filter = CreateEmployeePictureFilter(employeeId);
            GridFSFileInfo oldPictureInfo            = binaryFiles.Find(filter).SingleOrDefault();

            if (picture == null)
            {
                return(oldPictureInfo?.Id ?? ObjectId.Empty);
            }
            if (oldPictureInfo != null)
            {
                binaryFiles.Delete(oldPictureInfo.Id);
            }

            return(binaryFiles.UploadFromBytes(employeeId.ToString(), picture));
        }
Beispiel #10
0
        public void UploadFile(IFormFile file, string id)
        {
            try
            {
                var employerTemp = Get(id);
                if (employerTemp.IconUrl != null && employerTemp.IconType != null)
                {
                    bucket.Delete(ObjectId.Parse(employerTemp.IconUrl));
                }
            }
            catch (MongoDB.Driver.GridFS.GridFSFileNotFoundException) { }

            using (var stream = file.OpenReadStream())
            {
                var idFile = bucket.UploadFromStream(file.FileName, stream).ToString();

                var employerTemp = Get(id);
                employerTemp.IconUrl  = idFile;
                employerTemp.IconType = file.ContentType;
                _employers.ReplaceOne(employer => employer.Id == id, employerTemp);
            }
        }
Beispiel #11
0
 public static void DeleteFile(IRepository <Person> repository, ObjectId id)
 {
     bucket = new GridFSBucket(repository.Database);
     bucket.Delete(id);
 }
 public void Delete(TModel model)
 {
     gridFs.Delete(model.FileId);
     mongoCollection.DeleteOne(m => m.Id == model.Id);
 }