Exemplo n.º 1
0
        public Stream RetrieveSongFromDb(Song s)
        {
            MongoCollection songs  = DB.GetCollection <Song>("Song");
            var             gridFs = new MongoGridFs(dataBase);
            var             file   = gridFs.GetFile(new ObjectId(s.songRef));

            return(file);
        }
Exemplo n.º 2
0
        public static byte[] DownloadFile(MongoGridFs gridFs, MongoDB.Bson.ObjectId id)
        {
            byte[] buffer = null;

            using (System.IO.Stream file = gridFs.GetFile(id))
            {
                buffer = new byte[file.Length];
                // note - you'll probably want to read in
                // small blocks or stream to avoid
                // allocating large byte arrays like this
                file.Read(buffer, 0, (int)file.Length);
            } // End Using file

            return buffer;
        }
Exemplo n.º 3
0
        }         // End Sub DownloadFile

        public static byte[] DownloadFile(MongoGridFs gridFs, MongoDB.Bson.ObjectId id)
        {
            byte[] buffer = null;

            using (System.IO.Stream file = gridFs.GetFile(id))
            {
                buffer = new byte[file.Length];
                // note - you'll probably want to read in
                // small blocks or stream to avoid
                // allocating large byte arrays like this
                file.Read(buffer, 0, (int)file.Length);
            } // End Using file

            return(buffer);
        } // End Function DownloadFile
Exemplo n.º 4
0
        } // End Sub UploadFile

        public static void DownloadFile(MongoGridFs gridFs, MongoDB.Bson.ObjectId id, string path)
        {
            using (System.IO.Stream file = gridFs.GetFile(id))
            {
                int bytesRead = 0;
                int offset    = 0;

                const int BUFFER_SIZE = 1024 * 1024 * 10;
                byte[]    buffer      = new byte[BUFFER_SIZE];

                using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create))
                {
                    while ((bytesRead = (int)file.Read(buffer, offset, BUFFER_SIZE)) > 0)
                    {
                        fs.Write(buffer, 0, bytesRead);
                        offset += bytesRead;
                    } // Whend

                    fs.Close();
                } // End Using fs
            }     // End Using file
        }         // End Sub DownloadFile
Exemplo n.º 5
0
        public static void DownloadFile(MongoGridFs gridFs, MongoDB.Bson.ObjectId id, string path)
        {
            using (System.IO.Stream file = gridFs.GetFile(id))
            {
                int bytesRead = 0;
                int offset = 0;

                const int BUFFER_SIZE = 1024 * 1024 * 10;
                byte[] buffer = new byte[BUFFER_SIZE];

                using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create))
                {

                    while ((bytesRead = (int)file.Read(buffer, offset, BUFFER_SIZE)) > 0)
                    {
                        fs.Write(buffer, 0, bytesRead);
                        offset += bytesRead;
                    } // Whend

                    fs.Close();
                } // End Using fs

            } // End Using file
        }