Example #1
0
        public string UploadAudio()
        {
            string mp3      = null;
            string filePath = null;

            if (!string.IsNullOrEmpty(Request.Files[0].FileName))
            {
                HttpPostedFileBase file    = Request.Files[0];
                BinaryReader       b       = new BinaryReader(file.InputStream);
                byte[]             binData = b.ReadBytes(Convert.ToInt32(file.InputStream.Length));
                mp3 = System.Text.Encoding.UTF8.GetString(binData);
                byte[] binaryData   = Convert.FromBase64String(mp3.Replace("data:audio/mp3;base64,", ""));
                Stream sampleStream = new MemoryStream(binaryData);
                string audioName    = "Audio_" + DateTime.Now.Ticks + ".mp3";
                filePath = SharedSupport.SharedAudiosPath + audioName;
                string webpath = SharedSupport.GetAudioFolderPath() + audioName;
                using (FileStream writerStream = System.IO.File.Open(webpath, FileMode.CreateNew))
                {
                    Byte[] data = new Byte[binaryData.Count()];
                    for (byte i = 0; i < 100; i++)
                    {
                        Int32 readeDataLength = sampleStream.Read(data, 0, data.Count());
                        writerStream.Write(data, 0, readeDataLength);
                    }
                }
            }
            return(filePath);
        }