Пример #1
0
        public ActionResult Upload(BlobUploadModel model)
        {
            model.ContentFile = Request.Files["ContentFile"];
            if (model.ContentFile == null || model.ContentFile.ContentLength == 0)
            {
                ModelState.AddModelError("ContentFile", "Please select the file to upload.");
            }

            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            string filename = Path.GetFileName(model.ContentFile.FileName);
            var blobName = string.IsNullOrEmpty(model.Name) ? Path.GetFileNameWithoutExtension(model.ContentFile.FileName) : model.Name;

            var blob = new Blob()
            {
                Name = blobName,
                Description = model.Description,
                OriginalFileName = filename,
                UploadDateTime = DateTime.UtcNow
            };

            Guid blobId = this.blobService.UploadBlob(blob, model.ContentFile.InputStream);

            return RedirectToAction("Details", new { id = blobId });
        }
Пример #2
0
        public ActionResult Upload()
        {
            string message = null;

            if (Request.QueryString["FileTooLarge"] != null)
            {
                int maxRequestLength = 0;
                System.Web.Configuration.HttpRuntimeSection section =
                    (System.Web.Configuration.HttpRuntimeSection)
                    System.Web.Configuration.WebConfigurationManager.GetWebApplicationSection("system.web/httpRuntime");
                if (section != null)
                {
                    maxRequestLength = section.MaxRequestLength;
                }

                message = string.Format("File is too large. Use multiple file upload for files larger than {0}KB.", maxRequestLength);
            }

            var model = new BlobUploadModel
            {
                UploadHandler = this.GetUploadHandlerPage(),
                Message = message
            };

            return this.View(model);
        }