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 MongoDB.Bson.ObjectId UploadFile(MongoGridFs gridFs, string fileName)
        {
            MongoDB.Bson.ObjectId id = MongoDB.Bson.ObjectId.Empty;
            // UploadFile
            using (System.IO.Stream file = System.IO.File.OpenRead(fileName))
            {
                id = gridFs.AddFile(file, fileName);
            } // End Using file

            return id;
        }
Exemplo n.º 3
0
        } // End Sub Test

        public static MongoDB.Bson.ObjectId UploadFile(MongoGridFs gridFs, string fileName)
        {
            MongoDB.Bson.ObjectId id = MongoDB.Bson.ObjectId.Empty;
            // UploadFile
            using (System.IO.Stream file = System.IO.File.OpenRead(fileName))
            {
                id = gridFs.AddFile(file, fileName);
            } // End Using file

            return(id);
        } // End Sub UploadFile
Exemplo n.º 4
0
        protected void Unnamed1_Click(object sender, System.EventArgs e)
        {
            string fileName = @"D:\stefan.steiger\Downloads\keywords.xlsx";

            MongoDB.Driver.MongoClient   client   = new MongoDB.Driver.MongoClient("mongodb://localhost/27017/mydb");
            MongoDB.Driver.MongoServer   server   = client.GetServer();
            MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb");
            MongoGridFs gridFs = new MongoGridFs(database);

            MongoDB.Bson.ObjectId id = MongoGridFsUsage.UploadFile(gridFs, fileName);
            // byte[] baFile = DownloadFile(gridFs, id);
            // DownloadFile(gridFs, id, @"d:\test.rar");
        }
Exemplo n.º 5
0
        // http://odetocode.com/blogs/scott/archive/2013/04/16/using-gridfs-in-mongodb-from-c.aspx
        public static void Test()
        {
            string fileName = "clip_image071.jpg";

            MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient();
            MongoDB.Driver.MongoServer server = client.GetServer();
            MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb");
            MongoGridFs gridFs = new MongoGridFs(database);

            MongoDB.Bson.ObjectId id = UploadFile(gridFs, fileName);
            byte[] baFile = DownloadFile(gridFs, id);
            DownloadFile(gridFs, id, @"d:\test.rar");
        }
Exemplo n.º 6
0
        protected void Unnamed1_Click(object sender, System.EventArgs e)
        {
            string fileName = @"D:\stefan.steiger\Downloads\keywords.xlsx";

            MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient("mongodb://localhost/27017/mydb");
            MongoDB.Driver.MongoServer server = client.GetServer();
            MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb");
            MongoGridFs gridFs = new MongoGridFs(database);

            MongoDB.Bson.ObjectId id = MongoGridFsUsage.UploadFile(gridFs, fileName);
            // byte[] baFile = DownloadFile(gridFs, id);
            // DownloadFile(gridFs, id, @"d:\test.rar");
        }
Exemplo n.º 7
0
        // http://odetocode.com/blogs/scott/archive/2013/04/16/using-gridfs-in-mongodb-from-c.aspx
        public static void Test()
        {
            string fileName = "clip_image071.jpg";

            MongoDB.Driver.MongoClient   client   = new MongoDB.Driver.MongoClient();
            MongoDB.Driver.MongoServer   server   = client.GetServer();
            MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb");
            MongoGridFs gridFs = new MongoGridFs(database);


            MongoDB.Bson.ObjectId id = UploadFile(gridFs, fileName);
            byte[] baFile            = DownloadFile(gridFs, id);
            DownloadFile(gridFs, id, @"d:\test.rar");
        } // End Sub Test
Exemplo n.º 8
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.º 9
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.º 10
0
        public bool Add(Song song)
        {
            MongoCollection songs = DB.GetCollection <Song>("Song");

            //var testFileName = "C:\\Users\\Matija\\Downloads\\System Of A Down - Chop Suey!.mp3";  //sta ce radimo s ovim?
            var gridFs = new MongoGridFs(dataBase);

            var id   = ObjectId.Empty;
            var file = song.File;

            id           = gridFs.AddFile(file, song.Name);
            song.songRef = id.ToString();     // ovo mora se postavi ovako manuelno jer se tu gore generise
            song.File    = null;
            song.Likes   = 0;

            return(songs.Insert <Song>(song, SafeMode.True).Ok);
        }
Exemplo n.º 11
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.º 12
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
        }