Пример #1
0
        public void Download(string link)
        {
            if (link == null || link.IsNullOrWhiteSpace())
            {
                RedirectToAction("Upload");
            }
            else
            {
                File file = FileRepo.GetByUri(link);
                if (file == null)
                {
                    RedirectToAction("Upload");
                }
                else
                {
                    BlobRepo br = new BlobRepo("fubble");
                    CloudAppendBlob blob = br._container.GetAppendBlobReference(file.ObjectLink);

                    var memStream = new MemoryStream();
                    blob.DownloadToStream(memStream);

                    Response.ContentType = blob.Properties.ContentType;
                    Response.AddHeader("Content-Disposition", "Attachment;filename=" + file.ObjectLink + "." + file.Extension);
                    Response.AddHeader("Content-Length", blob.Properties.Length.ToString());
                    Response.BinaryWrite(memStream.ToArray());
                }
            }
        }
Пример #2
0
        public ActionResult FinishUpload(File item)
        {
            if (item == null)
            {
                return RedirectToAction("Upload");
            }
            try
            {
                BlobRepo br = new BlobRepo("fubble");
                item.CreatedDateTime = DateTime.Now;
                item.ExpirationDateTime = DateTime.Now.AddDays(14);
                item.Extension = item.Extension.Split('.').LastOrDefault();

                FileRepo.Add(item);

                return RedirectToAction("Details", "File", new { link = item.ObjectLink });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                ModelState.AddModelError("Error", ex.Message);
                TempData["ModelState"] = ModelState;
                return RedirectToAction("Upload");
            }
        }