public ActionResult Add()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageMedia, T("Couldn't upload media file")))
                return new HttpUnauthorizedResult();

            var viewModel = new MediaItemAddViewModel();
            try {
                UpdateModel(viewModel);

                if(String.IsNullOrWhiteSpace(Request.Files[0].FileName)) {
                    ModelState.AddModelError("File", T("Select a file to upload").ToString());
                }

                if (!ModelState.IsValid)
                    return View(viewModel);

                foreach (string fileName in Request.Files) {
                    _mediaService.UploadMediaFile(viewModel.MediaPath, Request.Files[fileName], viewModel.ExtractZip);
                }

                Services.Notifier.Information(T("Media file(s) uploaded"));
                return RedirectToAction("Edit", new { name = viewModel.FolderName, mediaPath = viewModel.MediaPath });
            } catch (Exception exception) {
                this.Error(exception, T("Uploading media file failed:"), Logger, Services.Notifier);

                return View(viewModel);
            }
        }
Beispiel #2
0
        public ContentResult AddFromClient() {
            if (!Services.Authorizer.Authorize(Permissions.ManageMedia))
                return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("ERROR: You don't have permission to upload media files")));

            var viewModel = new MediaItemAddViewModel();
            UpdateModel(viewModel);

            if (Request.Files.Count < 1 || Request.Files[0].ContentLength == 0)
                return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("HEY: You didn't give me a file to upload")));

            try {
                _mediaService.GetMediaFiles(viewModel.MediaPath);
            }
            catch //media api needs a little work, like everything else of course ;) <- ;) == my stuff included. to clarify I need a way to know if the path exists or have UploadMediaFile create paths as necessary but there isn't the time to hook that up in the near future
            {
                _mediaService.CreateFolder("", viewModel.MediaPath);
            }

            var file = Request.Files[0];
                
            try {
                var publicUrl = _mediaService.UploadMediaFile(viewModel.MediaPath, file, viewModel.ExtractZip);
                return Content(string.Format("<script type=\"text/javascript\">var result = {{ url: \"{0}\" }};</script>", publicUrl));
            }
            catch (ArgumentException argumentException) {
                return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("ERROR: Uploading media file failed: {0}", argumentException.Message)));
            }
        }
Beispiel #3
0
        public ActionResult Add(string folderName, string mediaPath) {
            if (!Services.Authorizer.Authorize(Permissions.ManageMedia, T("Couldn't upload media file")))
                return new HttpUnauthorizedResult();
            
            var currentSite = Services.WorkContext.CurrentSite;

            var model = new MediaItemAddViewModel {
                FolderName = folderName, 
                MediaPath = mediaPath,
                AllowedExtensions = currentSite.As<MediaSettingsPart>().UploadAllowedFileTypeWhitelist
            };

            if(currentSite.SuperUser.Equals(Services.WorkContext.CurrentUser.UserName, StringComparison.Ordinal)) {
                model.AllowedExtensions = String.Empty;
            }

            return View(model);
        }
        public ActionResult Add() {
            var viewModel = new MediaItemAddViewModel();
            try {
                UpdateModel(viewModel);
                if (!Services.Authorizer.Authorize(Permissions.UploadMediaFiles, T("Couldn't upload media file")))
                    return new HttpUnauthorizedResult();

                if(Request.Files[0].FileName.IsNullOrEmptyTrimmed()) {
                    ModelState.AddModelError("File", T("Select a file to upload").ToString());
                }

                if (!ModelState.IsValid)
                    return View(viewModel);

                foreach (string fileName in Request.Files) {
                    HttpPostedFileBase file = Request.Files[fileName];
                    _mediaService.UploadMediaFile(viewModel.MediaPath, file);
                }

                return RedirectToAction("Edit", new { name = viewModel.FolderName, mediaPath = viewModel.MediaPath });
            }
            catch (Exception exception) {
                Services.Notifier.Error("Uploading media file failed: " + exception.Message);
                return View(viewModel);
            }
        }
 public ActionResult Add(string folderName, string mediaPath) {
     var model = new MediaItemAddViewModel { FolderName = folderName, MediaPath = mediaPath };
     return View(model);
 }