Exemplo n.º 1
0
 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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        public byte[] DownloadFile(string id)
        {
            var employerTemp = Get(id);
            var bytes        = bucket.DownloadAsBytes(ObjectId.Parse(employerTemp.IconUrl));

            return(bytes);
        }
Exemplo n.º 5
0
 public Task <byte[]> GetFile(ObjectId id)
 {
     return(Task.Run(() =>
     {
         return gridFS.DownloadAsBytes(id);
     }));
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public byte[] GetFile(ObjectId id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            return(_gridFsBucket.DownloadAsBytes(id));
        }
Exemplo n.º 8
0
 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));
            }
        }
Exemplo n.º 10
0
        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));
 }
Exemplo n.º 12
0
 public byte[] Downloadfile(string idFile)
 {
     return(bucket.DownloadAsBytes(ObjectId.Parse(idFile)));
 }