We’ve noticed that if you add a File Upload field type to an umbraco forms form and specifically say the file upload can only accept “JPG” - The JPEG file type is not automatically included as part of that.
Of course JPEG can be manually added each time however in site situations where you have multiple forms this can be a bit of a tedious annoyance. Wondering if anyone knows how you can automatically add JPEG alongside JPG validation?
Especially as they are considered the same file type.
I don’t think there’s a way to add it automatically to the config. I supposed you could write some code that uses the form service to modify the forms if you have a lot.
Maybe something like this would work? Just a guess, not tested.
public class MyUpload : Umbraco.Forms.Core.Providers.FieldTypes.FileUpload
{
public MyUpload(IOptions<SecuritySettings> config, IHostEnvironment hostEnvironment, MediaFileManager mediaFileManager, IDataProtectionProvider dataProtectionProvider, IFileStreamSecurityValidator fileStreamSecurityValidator) : base(config, hostEnvironment, mediaFileManager, dataProtectionProvider, fileStreamSecurityValidator)
{
}
public override IEnumerable<string> ValidateField(Form form, Field field, IEnumerable<object> postedValues, HttpContext context, IPlaceholderParsingService placeholderParsingService, IFieldTypeStorage fieldTypeStorage)
{
if (field.AllowedUploadTypes.Any(x => x.Type == "jpg"))
{
field.AllowedUploadTypes = field.AllowedUploadTypes.Append(new AllowedUploadType { Checked = "true", Name = "JPEG", Type = "jpeg" });
}
return base.ValidateField(form, field, postedValues, context, placeholderParsingService, fieldTypeStorage);
}
}
I’d flag this as an issue either way - as you say the jpeg/jpg distinction shouldn’t be relevant here.
Thanks, ill give it a try! Thankfully a lot of this is on Umbraco cloud baseline sites so after checking if this line of working works, Should be able to role something like this out.