The Upload file
and Upload files (advanced)
use different methods for communication between the frontend and backend for the alerts that are shown.
The advanced upload will display whatever you set in args.ErrorText
but Upload files through a slightly roundabout way calls ShowFileTooBig(string filename)
in Sitecore.Shell.Applications.Media.UploadMedia.UploadMediaForm
.
Provide a new implmentation of the ShowFileTooBig
method and add in the same validation as you do in your pipeline and show the correct message:
public class UploadMediaForm : Sitecore.Shell.Applications.Media.UploadMedia.UploadMediaForm
{
private string ErrorMessage = "The image \"{0}\" is too big to be uploaded. The maximum size for uploading images is {1}.";
protected new void ShowFileTooBig(string filename)
{
string extension = Path.GetExtension(filename);
if (!extension.Equals(".jpg"))
{
base.ShowFileTooBig(filename);
return;
}
SheerResponse.Alert(Translate.Text(ErrorMessage, filename, MainUtil.FormatSize(ImageSettings.MaxImageSizeInDatabase)));
this.OK.Disabled = true;
this.Cancel.Disabled = true;
this.OK.Disabled = false;
this.Cancel.Disabled = false;
}
}
Create a copy of /sitecore/shell/Applications/Media/Upload Media/UploadMedia.xml and place it in /sitecore/shell/Override. Edit the file and update the type specified in the CodeBeside
tag to your own implementation. We need to provide a new implementation of the ShowFileTooBig
method.
I've made an assumption that you have a custom uiUpload
pipeline processor that checks the file being uploaded and returns the error. You can find a Github Gist with a fuller code example but the above should answer your specific question.
Note that your question only deals with the simple HTML version of the uploader. You also need to deal with the Flash enabled uploader. This requires further updates similar to this StackOverflow answer I previosuly provided.