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); }
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 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
} // 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
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 }