Esempio n. 1
0
        private static async void DownloadFile(GridFSBucket fs, ObjectId id, string naziv)
        {
            byte[] content = await fs.DownloadAsBytesByNameAsync(naziv + ".pdf");

            File.WriteAllBytes(@"C:\Users\38160\Downloads" + naziv + ".pdf", content);
            System.Diagnostics.Process.Start(@"C:\Users\38160\Downloads" + naziv + ".pdf");
        }
        /// <summary>
        /// GridFS文件操作——下载 异步
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        async public Task <byte[]> DownLoadAsync(string fileName)
        {
            var gridfs = new GridFSBucket(database);

            byte[] fileData = await gridfs.DownloadAsBytesByNameAsync(fileName);

            return(fileData);
        }
Esempio n. 3
0
        public async Task <FileModel> FindOneAsync(IPrincipal user, string id)
        {
            byte[] bytes = await _bucket.DownloadAsBytesByNameAsync(id);

            return(new FileModel {
                Name = id, Contents = bytes, Size = bytes.Length
            });
        }
Esempio n. 4
0
        public async Task <IActionResult> FSDown()
        {
            var    mongo       = new MongoDBTool().GetMongoDatabase();
            var    bucket      = new GridFSBucket(mongo);
            string newJsonPath = $@"{hostingEnvironment.ContentRootPath}/wwwroot/account/car_number_new.json";

            byte[] data = await bucket.DownloadAsBytesByNameAsync("car_number_new");

            return(File(data, "application/json", "car_number_new.json"));
        }
        public static async Task DownloadFileAsBytesByName()
        {
            var database = DatabaseHelper.GetDatabaseReference("localhost", "file_store");

            IGridFSBucket bucket = new GridFSBucket(database);

            byte[] content = await bucket.DownloadAsBytesByNameAsync("sample2.pdf");

            File.WriteAllBytes("C:\\temp\\sample2.pdf", content);

            //System.Diagnostics.Process.Start("C:\\temp\\sample2.pdf");
        }
Esempio n. 6
0
        private static void DownloadFile(GridFSBucket fs, ObjectId id)
        {
            //This works
            var t = fs.DownloadAsBytesByNameAsync("test.txt");

            Task.WaitAll(t);
            var bytes = t.Result;


            //This blows chunks (I think it's a driver bug, I'm using 2.1 RC-0)
            var x = fs.DownloadAsBytesAsync(id);

            Task.WaitAll(x);
        }
Esempio n. 7
0
        private static Image DownloadFile(GridFSBucket fs, ObjectId id, string naziv)
        {
            //This works
            var t = fs.DownloadAsBytesByNameAsync(naziv + ".jpg");

            Task.WaitAll(t);
            var bytes = t.Result;

            using (var newFs = new FileStream(naziv, FileMode.Create))
            {
                newFs.Write(bytes, 0, bytes.Length);
                Image image = Image.FromStream(newFs);
                return(image);
            }
        }
        public List <byte[]> DownloadFile(GridFSBucket fs, List <ObjectId> id)
        {
            string        path    = @"G:\Projekty\WebAppParser\Content\images\";
            List <string> files   = Utils.FilesInFolder(path);
            List <byte[]> result  = new List <byte[]>();
            int           counter = 0;

            foreach (string file in files)
            {
                var t = fs.DownloadAsBytesByNameAsync(file);
                Task.WaitAll(t);
                var bytes = t.Result;
                var x     = fs.DownloadAsBytesAsync(id[counter++]);
                Task.WaitAll(x);
                result.Add(x.Result);
            }

            return(result);
        }
        public static Image ImageGridFS(string photoID)
        {
            Image      p = null;
            FileStream f;

            try
            {
                var t = gridFS.DownloadAsBytesByNameAsync(photoID);
                Task.WaitAll(t);
                var bytes = t.Result;

                using (f = new FileStream(photoID, FileMode.Create))
                {
                    f.Write(bytes, 0, bytes.Length);
                    p = Image.FromStream(f);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in MongoDBTransactions.ImageGridFS() method :: " + e.Message);
            }
            return(p);
        }
 protected Task <byte[]> InvokeMethodAsync(GridFSBucket bucket)
 {
     return(bucket.DownloadAsBytesByNameAsync(_filename, _options));
 }
Esempio n. 11
0
        public async Task ThenMessageStoredAsExpected()
        {
            var result = await _bucket.DownloadAsBytesByNameAsync(_filename);

            Assert.That(result, Is.EqualTo(_expectedData));
        }
Esempio n. 12
0
 public Task <byte[]> Get(string fileId)
 {
     return(_gridFs.DownloadAsBytesByNameAsync(fileId));
 }
 protected override async Task CallMethodAsync(CancellationToken cancellationToken)
 {
     var bucket = new GridFSBucket(_database, _bucketOptions);
     await bucket.DownloadAsBytesByNameAsync(_fileName, _downloadOptions, cancellationToken).ConfigureAwait(false);
 }
Esempio n. 14
0
        /// <summary>
        /// Downloads a file stored in GridFS and returns it as a byte array.
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public Task <byte[]> DownloadAsBytesByNameAsync(string filename, GridFSDownloadByNameOptions options = null)
        {
            var bucket = new GridFSBucket(base.GetDatabase(), BucketOptions);

            return(bucket.DownloadAsBytesByNameAsync(filename, options));
        }
 protected Task<byte[]> InvokeMethodAsync(GridFSBucket bucket)
 {
     return bucket.DownloadAsBytesByNameAsync(_filename, _options);
 }