public byte[] DownloadFile(string id, string collection) { if (collection == "topic") { return(bucket.DownloadAsBytes(ObjectId.Parse(GetTopic(id).IconUrl))); } return(bucket.DownloadAsBytes(ObjectId.Parse(GetEmployer(id).IconUrl))); }
public byte[] DownloadFileById(string filestoreid, EbFileCategory cat) { byte[] res = null; try { Bucket = new GridFSBucket(mongoDatabase, new GridFSBucketOptions { BucketName = cat.ToString(), ChunkSizeBytes = 1048576, // 1MB WriteConcern = WriteConcern.WMajority, ReadPreference = ReadPreference.Secondary }); ObjectId objId = new ObjectId(filestoreid); res = Bucket.DownloadAsBytes(objId, new GridFSDownloadOptions() { CheckMD5 = true }); } catch (GridFSFileNotFoundException e) { Console.WriteLine("MongoDB File Not Found: " + filestoreid.ToString() + e.Message + e.StackTrace); } catch (Exception e) { Console.WriteLine("Exception:" + e.Message + e.StackTrace); } return(res); }
/// <summary> /// Get all files from database by their ids as photo models. /// </summary> /// <param name="fileIds">Ids of the files to be find.</param> /// <returns></returns> public async Task <IEnumerable <Photo> > GetPhotosByIds(IEnumerable <ObjectId> fileIds) { var resultList = new List <Photo>(); foreach (var fileId in fileIds) { var fileContent = _gridFs.DownloadAsBytes(fileId); var filter = Builders <GridFSFileInfo> .Filter.Eq("_id", ObjectId.Parse(fileId.ToString())); var fileInfo = _gridFs.Find(filter).FirstOrDefault(); if (fileInfo != null) { var photoModel = new Photo { Id = fileInfo.Id.ToString(), Content = fileContent, FileName = fileInfo.Filename }; resultList.Add(photoModel); } } return(resultList); }
public byte[] DownloadFile(string id) { var employerTemp = Get(id); var bytes = bucket.DownloadAsBytes(ObjectId.Parse(employerTemp.IconUrl)); return(bytes); }
public Task <byte[]> GetFile(ObjectId id) { return(Task.Run(() => { return gridFS.DownloadAsBytes(id); })); }
public static byte[] GetFile(IRepository <Person> repository, ObjectId id) { bucket = new GridFSBucket(repository.Database); //bucket.DownloadToStream(id, stream); var bytes = bucket.DownloadAsBytes(id); return(bytes); }
public byte[] GetFile(ObjectId id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } return(_gridFsBucket.DownloadAsBytes(id)); }
public byte[] GetJpegById(String id) { try { var imagebinary = bucket.DownloadAsBytes(new ObjectId(id)); return(imagebinary); } catch (Exception e) { Console.WriteLine($"Failed to find image with id {id}. Error {e.ToString()}"); return(new byte[0]); } }
public OperationResult Execute(CancellationToken cancellationToken) { try { var result = _bucket.DownloadAsBytes(_id, cancellationToken: cancellationToken); return(OperationResult.FromResult(BsonUtils.ToHexString(result))); } catch (Exception exception) { return(OperationResult.FromException(exception)); } }
public byte[] DownloadFile(ObjectId objectid, string bucketName) { Bucket = new GridFSBucket(mongoDatabase, new GridFSBucketOptions { BucketName = bucketName, ChunkSizeBytes = 1048576, // 1MB WriteConcern = WriteConcern.WMajority, ReadPreference = ReadPreference.Secondary }); return(Bucket.DownloadAsBytes(objectid, new GridFSDownloadOptions() { CheckMD5 = true })); }
public byte[] GetFile(ObjectId fileId) { return(gridFs.DownloadAsBytes(fileId)); }
public byte[] Downloadfile(string idFile) { return(bucket.DownloadAsBytes(ObjectId.Parse(idFile))); }