Beispiel #1
0
        public async Task <ActionResult> UploadVideo()
        {
            var    data         = Request.Form.Files["data"];
            string lastModified = Request.Form["lastModified"].ToString();
            var    total        = Request.Form["total"];
            var    fileName     = Request.Form["fileName"];
            var    index        = Request.Form["index"];
            string temporary    = Path.Combine(Directory.GetCurrentDirectory() + $@"\Files\Video\", lastModified);//临时保存分块的目录

            try
            {
                if (!Directory.Exists(temporary))
                {
                    Directory.CreateDirectory(temporary);
                }
                string filePath = Path.Combine(temporary, index.ToString());
                if (!Convert.IsDBNull(data))
                {
                    await Task.Run(() => {
                        FileStream fs = new FileStream(filePath, FileMode.Create);
                        data.CopyTo(fs);
                        fs.Close();
                    });
                }
                bool mergeOk = false;
                if (total == index)
                {
                    mergeOk = await _uploadService.FileMerge(lastModified, fileName);
                }

                Dictionary <string, object> result = new Dictionary <string, object>();
                result.Add("number", Convert.ToInt32(index.ToString()));
                result.Add("mergeOk", mergeOk);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Directory.Delete(temporary);//删除文件夹
                throw ex;
            }
        }