Beispiel #1
0
        private void button9_Click(object sender, EventArgs e)
        {
            FileStream stream;
            OpenFileDialog ofd = new OpenFileDialog();
            var client = new MongoClient("mongodb://localhost");
            var database = client.GetDatabase("docs");
            var fs = new GridFSBucket(database);
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                stream = new System.IO.FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
                //SoundPlayer simpleSound = new SoundPlayer(stream);
                //simpleSound.Play();
                var split = ofd.SafeFileName.Split('.');
                if(split[1] != "mp3")
                {
                    MessageBox.Show("Izaberite mp3 fajl!");
                    return;
                }
                GridFSUploadOptions opcije = new GridFSUploadOptions();
                opcije.ContentType = "audio/mp3";
                opcije.ChunkSizeBytes = Convert.ToInt32(stream.Length)/4;

                int duzina = Convert.ToInt32(stream.Length);
                byte[] bajtovi = new byte[duzina];
                stream.Seek(0, SeekOrigin.Begin);
                int bytesRead = stream.Read(bajtovi, 0, duzina);

                fs.UploadFromBytes(ofd.SafeFileName, bajtovi, opcije);

            }
        }
Beispiel #2
0
        private void button8_Click(object sender, EventArgs e)
        {
            Image slika;
            FileStream stream;
            var client = new MongoClient("mongodb://localhost");
            var database = client.GetDatabase("docs");
            var fs = new GridFSBucket(database);
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                stream = new System.IO.FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
                slika = Image.FromStream(stream);

                GridFSUploadOptions opcije = new GridFSUploadOptions();
                opcije.ContentType = "image/jpg";
                opcije.ChunkSizeBytes = Convert.ToInt32(stream.Length);

                int duzina = Convert.ToInt32(stream.Length);
                byte[] bajtovi = new byte[duzina];
                stream.Seek(0, SeekOrigin.Begin);
                int bytesRead = stream.Read(bajtovi, 0, duzina);

                fs.UploadFromBytes("Test", bajtovi, opcije);

            }
            MessageBox.Show("done");
        }