コード例 #1
0
ファイル: ImgService.cs プロジェクト: PaulLol/Csharp
 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)));
 }
コード例 #2
0
        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);
        }
コード例 #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);
        }
コード例 #4
0
ファイル: EmployerService.cs プロジェクト: PaulLol/Csharp
        public byte[] DownloadFile(string id)
        {
            var employerTemp = Get(id);
            var bytes        = bucket.DownloadAsBytes(ObjectId.Parse(employerTemp.IconUrl));

            return(bytes);
        }
コード例 #5
0
 public Task <byte[]> GetFile(ObjectId id)
 {
     return(Task.Run(() =>
     {
         return gridFS.DownloadAsBytes(id);
     }));
 }
コード例 #6
0
ファイル: FileTools.cs プロジェクト: firefield2/MainApp
        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);
        }
コード例 #7
0
        public byte[] GetFile(ObjectId id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            return(_gridFsBucket.DownloadAsBytes(id));
        }
コード例 #8
0
ファイル: MongoDBInterface.cs プロジェクト: s-sangam/MBG
 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]);
     }
 }
コード例 #9
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));
            }
        }
コード例 #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
            }));
        }
コード例 #11
0
 public byte[] GetFile(ObjectId fileId)
 {
     return(gridFs.DownloadAsBytes(fileId));
 }
コード例 #12
0
ファイル: MusicService.cs プロジェクト: PaulLol/Csharp
 public byte[] Downloadfile(string idFile)
 {
     return(bucket.DownloadAsBytes(ObjectId.Parse(idFile)));
 }