public new void Process(UploadArgs args) { if (Sitecore.UIUtil.IsIE()) { // We need to use the original functionality for IE base.Process(args); return; } Assert.ArgumentNotNull((object)args, "args"); if (args.Destination == UploadDestination.File) { return; } foreach (string index in (NameObjectCollectionBase)args.Files) { HttpPostedFile file = args.Files[index]; if (!string.IsNullOrEmpty(file.FileName)) { if (UploadProcessor.IsUnpack(args, file)) { ZipReader zipReader = new ZipReader(file.InputStream); try { foreach (ZipEntry zipEntry in zipReader.Entries) { if (!zipEntry.IsDirectory && zipEntry.Size > Settings.Media.MaxSizeInDatabase) { string text = file.FileName + "/" + zipEntry.Name; HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.browser.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig(" + StringUtil.EscapeJavascriptString(text) + ")')</script></head><body>Done</body></html>"); args.ErrorText = string.Format("The file \"{0}\" is too big to be uploaded. The maximum size for uploading files is {1}.", (object)text, (object)MainUtil.FormatSize(Settings.Media.MaxSizeInDatabase)); args.AbortPipeline(); return; } } } finally { file.InputStream.Position = 0L; } } else if ((long)file.ContentLength > Settings.Media.MaxSizeInDatabase) { string fileName = file.FileName; HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.browser.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig(" + StringUtil.EscapeJavascriptString(fileName) + ")')</script></head><body>Done</body></html>"); args.ErrorText = string.Format("The file \"{0}\" is too big to be uploaded. The maximum size for uploading files is {1}.", (object)fileName, (object)MainUtil.FormatSize(Settings.Media.MaxSizeInDatabase)); args.AbortPipeline(); break; } } } }
public void Process(UploadArgs args) { Assert.ArgumentNotNull((object)args, nameof(args)); if (args.Destination == UploadDestination.File) { return; } foreach (string file1 in args.Files) { HttpPostedFile file2 = args.Files[file1]; if (!string.IsNullOrEmpty(file2.FileName)) { if (UploadProcessor.IsUnpack(args, file2)) { ZipReader zipReader = new ZipReader(file2.InputStream); try { foreach (ZipEntry entry in zipReader.Entries) { if (!entry.IsDirectory && !UploadFileSettings.IsAllowedFile(entry.Name, entry.Size)) { string text = file2.FileName + "/" + entry.Name; args.UiResponseHandlerEx.FileTooBigForUpload(StringUtil.EscapeJavascriptString(text)); args.ErrorText = UploadFileSettings.FileErrorMessage(file2.FileName); args.AbortPipeline(); return; } } } finally { file2.InputStream.Position = 0L; } } else if (!UploadFileSettings.IsAllowedFile(file2)) { string fileName = file2.FileName; if (HttpContext.Current.Request.Url.AbsolutePath != "/sitecore/shell/api/sitecore/Media/Upload") { args.UiResponseHandlerEx.FileTooBigForUpload(StringUtil.EscapeJavascriptString(fileName)); } args.ErrorText = UploadFileSettings.FileErrorMessage(file2.FileName); args.AbortPipeline(); break; } } } }
private void UploadImage(UploadArgs args, HttpPostedFile file, string krakedImgePath) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(file, "file"); var newFile = DownloadAndCreateFile(krakedImgePath, file); if (newFile == null) { base.Process(args); } else { bool flag = UploadProcessor.IsUnpack(args, newFile); var altText = args.GetFileParameter(file.FileName, "alt"); MediaUploader mediaUploader = new MediaUploader { File = newFile, Unpack = flag, Folder = args.Folder, Versioned = args.Versioned, Language = args.Language, AlternateText = !(string.IsNullOrEmpty(altText)) ? altText : file.FileName, Overwrite = args.Overwrite, FileBased = args.Destination == UploadDestination.File }; System.Collections.Generic.List <MediaUploadResult> list; using (new SecurityDisabler()) { list = mediaUploader.Upload(); } Log.Audit(this, "Upload: {0}", new string[] { file.FileName }); foreach (MediaUploadResult current in list) { this.ProcessItem(args, current.Item, current.Path); } } }
public void Process(UploadArgs args) { Assert.ArgumentNotNull((object)args, "args"); for (int index = 0; index < args.Files.Count; ++index) { HttpPostedFile file = args.Files[index]; if (!string.IsNullOrEmpty(file.FileName)) { try { bool flag = UploadProcessor.IsUnpack(args, file); if (args.FileOnly) { if (flag) { Save.UnpackToFile(args, file); } else { string uploadFile = this.UploadToFile(args, file); if (index == 0) { args.Properties["filename"] = (object)FileHandle.GetFileHandle(uploadFile); } } } else { byte[] fileData = null; file.InputStream.Position = 0; using (var binaryReader = new BinaryReader(file.InputStream)) { fileData = binaryReader.ReadBytes(file.ContentLength); } if (fileData == null) { Log.Error($"Could not process the saved posted file {file.FileName}", null, (object)this); return; } byte[] compressedBytes = _compressionManager.OptimizeImage(fileData); //List<Sitecore.Resources.Media.MediaUploadResult> mediaUploadResultList; using (new SecurityDisabler()) Upload(file, compressedBytes, flag, args, (args.Destination == UploadDestination.File)); Log.Audit((object)this, "Upload: {0}", new string[1] { file.FileName }); //foreach (Sitecore.Resources.Media.MediaUploadResult mediaUploadResult in mediaUploadResultList) // this.ProcessItem(args, (MediaItem)mediaUploadResult.Item, mediaUploadResult.Path); } } catch (Exception ex) { Log.Error($"Could not save posted file: {file.FileName}", ex, (object)this); throw; } } } }
/// <summary> /// Runs the processor. /// </summary> /// <param name="args">The arguments.</param> /// <exception cref="T:System.Exception"><c>Exception</c>.</exception> public void Process(UploadArgs args) { Assert.ArgumentNotNull(args, "args"); for (int i = 0; i < args.Files.Count; i++) { HttpPostedFile httpPostedFile = args.Files[i]; if (!string.IsNullOrEmpty(httpPostedFile.FileName)) { try { bool flag = UploadProcessor.IsUnpack(args, httpPostedFile); if (args.FileOnly) { if (flag) { Save.UnpackToFile(args, httpPostedFile); } else { string filename = this.UploadToFile(args, httpPostedFile); if (i == 0) { args.Properties["filename"] = FileHandle.GetFileHandle(filename); } } } else { MediaUploader mediaUploader = new MediaUploader { File = httpPostedFile, Unpack = flag, Folder = args.Folder, Versioned = args.Versioned, Language = args.Language, AlternateText = args.GetFileParameter(httpPostedFile.FileName, "alt"), Overwrite = args.Overwrite, FileBased = args.Destination == UploadDestination.File }; System.Collections.Generic.List <MediaUploadResult> list; using (new SecurityDisabler()) { list = mediaUploader.Upload(); } Log.Audit(this, "Upload: {0}", new string[] { httpPostedFile.FileName }); foreach (MediaUploadResult current in list) { this.ProcessItem(args, current.Item, current.Path); } } } catch (System.Exception exception) { Log.Error("Could not save posted file: " + httpPostedFile.FileName, exception, this); throw; } } } }