本文介绍了Sitecore管道上传处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用UploadProcessor阻止将特定文件上传到MediaLibrary。 一切正常,我可以看到警报Sitecore的消息。但是,Sitecore的错误消息并不是真正的用户友好型无法上传一个或多个文件。有关更多详细信息,请参阅日志文件。 因此,我想为用户添加额外的警报框。下面是我的代码,但是javascript无法正常工作。 有些人希望我使用 SheerResponse,但Sitecore文档提到了 uiUpload管道不是作为Sheer事件的一部分运行的,而是作为响应回发的表单加载过程的一部分而运行的。这是因为上载的文件仅在真实回发期间可用,而在纯粹的UI事件期间不可用。从这个意义上说,uiUpload管道尚未设计为提供UI。为了向用户提供反馈,处理器应采取一些技巧来发出JScript代码。 http:// sdn。 sitecore.net/Articles/Media/Prevent%20Files%20from%20Uploading/Pipeline%20upload.aspx 有任何想法如何实现警报框吗?解决方案媒体库中的Upload控件使用Flash上传文件。在此上传过程中,将使用JavaScript检查文件大小,并在上传之前进行客户端验证。 您需要进行许多更改。 。我将在这里列出它们,您可以在我的Github Gists中找到所有代码: https://gist.github.com/jammykam/54d6af46593fa3b827b4 1)扩展并更新 MediaFolder.js 文件,仅在扩展名是1的情况下对照图像大小检查文件大小在配置中指定 if(file.size> this.uploadLimit()|| this.uploadImageLimitReached(file)){ ... } 2)更新 MediaFolder.xml 页以包含上述JS。修改代码旁边的内容,从 Sitecore.Shell.Applications.Media.MediaFolder.MediaFolderForm 继承并覆盖 OnLoad 和 OnFilesCancelled ,以呈现受限制的扩展名和最大图像大小设置,以便将这些设置传递给Javascript并显示友好的警报。 settings.Add( uploadImageLimit,((long)System.Math.Min(ImageSettings.MaxImageSizeInDatabase,Settings.Runtime.EffectiveMaxRequestLengthBytes))。ToString()); settings.Add( uploadImageRestrictedExtensions,ImageSettings.RestrictedImageExtensions); 3)更新 Attach.xaml.xml 代码可检查图像大小,继承自 Sitecore.Shell.Applications.FlashUpload.Attach.AttachPage 并覆盖 OnQueued 方法: if(ImageSettings.IsRestrictedExtension(filename)&& num> maximumImageUploadSize) {字符串text = Translate.Text(图像\ {0} \太大,无法上传。\n\n可以上传的最大图像尺寸为{1} 。,新对象[] {文件名,MainUtil.FormatSize(maximumImageUploadSize)}); this.WarningMessage = text; SheerResponse.Alert(文本,新字符串[0]); } else { base.OnQueued(filename,lengthString); } 4)添加新配置 <设置名称= Media.MaxImageSizeInDatabase value = 1MB /> < setting name = Media.RestrictedImageExtensions value =。jpg | .jpeg | .png | .gif | .bmp | .tiff /> 您仍然(并且应该)保持管道到位,但从我的上一个答案中注意到,我给受限扩展配置设置现已更改(变为单个设置而不是将其传递到管道中)。要点包含 注意,我已经使用Sitecore 7.2修订版140526对它进行了测试,因此基本代码是从此处获取的。如果您使用的是其他版本,则应检查基本的C#,JS和XML代码是否与我提供的代码匹配。该代码被注释以向您显示已更改的内容。 以上内容在内容编辑器中有效,而在页面编辑器中无效! Sitecore 7.2+中的哪个使用SPEAK对话框,看起来它们使用了不同的管道集。那将需要更多的调查(提出另一个问题,并指定您使用的Sitecore版本)。 I'm using UploadProcessor to block specific file uploading into MediaLibrary.Everything is working good and I can see the alert Sitecore's message. But, Sitecore's error message is not really user-friendly "One or more files could not be uploaded. See the Log file for more details"So, I'd like to add extra alert box for users. Below is my code, but the javascript is not working.Some people want me to use "SheerResponse", but Sitecore Document mentions that The uiUpload pipeline is run not as part of the Sheer event, but as part of the form loading process in response to a post back. This is because the uploaded files are only available during the "real" post back, and not during a Sheer UI event. In this sense, the uiUpload pipeline has not been designed to provide UI. In order to provide feedback to a User, the processor should resort to some trick which emits the JScript code. http://sdn.sitecore.net/Articles/Media/Prevent%20Files%20from%20Uploading/Pipeline%20upload.aspxDo you have any idea how to implement alert box?? 解决方案 The Upload control in the Media Library uses flash to upload the files. As part of this upload process, the file sizes are checked using JavaScript and a client side validation is made before the upload.There are a number of changes you need to make. I'm just going to list them here, you can find all the code in my Github Gists:https://gist.github.com/jammykam/54d6af46593fa3b827b41) Extend and update the MediaFolder.js file to check the file size against the Image Size ONLY if the extension is one specified in configif (file.size > this.uploadLimit() || this.uploadImageLimitReached(file)) { ...}2) Update MediaFolder.xml page to include the above JS. Amend the codebeside, inheriting from Sitecore.Shell.Applications.Media.MediaFolder.MediaFolderForm and overriding OnLoad and OnFilesCancelled, to render restricted extensions and max image size settings so these are passed to the Javascript and display friendly alert.settings.Add("uploadImageLimit", ((long)System.Math.Min(ImageSettings.MaxImageSizeInDatabase, Settings.Runtime.EffectiveMaxRequestLengthBytes)).ToString());settings.Add("uploadImageRestrictedExtensions", ImageSettings.RestrictedImageExtensions);3) Update Attach.xaml.xml codebeside to check image size, inheriting from Sitecore.Shell.Applications.FlashUpload.Attach.AttachPage and overriding OnQueued method:if (ImageSettings.IsRestrictedExtension(filename) && num > maximumImageUploadSize){ string text = Translate.Text("The image \"{0}\" is too big to be uploaded.\n\nThe maximum image size that can be uploaded is {1}.", new object[] { filename, MainUtil.FormatSize(maximumImageUploadSize) }); this.WarningMessage = text; SheerResponse.Alert(text, new string[0]);}else{ base.OnQueued(filename, lengthString);}4) Add a config include with the new settings.<setting name="Media.MaxImageSizeInDatabase" value="1MB" /><setting name="Media.RestrictedImageExtensions" value=".jpg|.jpeg|.png|.gif|.bmp|.tiff" />You can still (and should) keep the pipelines in place, but note from my previous answer I gave the "Restricted Extension" config setting has now changed (into a single setting instead of passing it into the pipeline). The Gist contains theNOTE that I have tested this using Sitecore 7.2 rev 140526, so the base code is taken from there. If you are using a different version then you should check the base C#, JS and XML code matches what I have provided. The code is commented to show you what has changed.The above works in the Content Editor, it does not work in the Page Editor! Which in Sitecore 7.2+ uses SPEAK dialogs and it looks like they use a different set of pipelines. That would need more investigation (raise another question, and specify which version of Sitecore you are using). 这篇关于Sitecore管道上传处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 20:14