Binary File Naming
Binary file naming controls the rules that are applied to the naming convention for binary files such as pictures, movies, and PDF files. This limits the ability to upload binary files to those that comply with a specific file naming convention, such as using a rule that all letters must be lower case. This also allows administrators to ensure that the file naming convention is enforced when binary files are renamed, which can be accomplished with the Image Editor for image binaries and through the folder structure. The Binary File Naming feature is enforced whether Binary Management is enabled or disabled. If Binary Management is disabled, the regex is still used even though the files are published immediately to the production server.
Note: The Text Regex field becomes available after entering text in the Binary File Name Regex field during site creation.
About Regular Expressions
Binary File Naming uses regular expressions, often referred to as regex, to control the characters allowed in the naming of a file. A commonly used regular expression in file naming is: [a-z0-9\-_.]*
This particular regular expression allows for the file name to include lowercase letters, numbers 0–9, hyphens, underscores, and periods. All other characters are disallowed and present the user with a warning message.
Note that just as with non-binary file naming, certain characters are automatically excluded from OU Campus, and cannot be used for any filename, regardless of the custom regex being used. These characters are as follows:
Binary File Naming Reference
Binary File Name Regex: A regular expression (regex) can be input into this field to have binary files conform to a file naming convention. Regular expressions allow specification of whether or not letters, numbers, capitalization, etc., are allowed for binary file naming. A commonly used regex allows for lowercase letters, numbers, hyphens, underscores, and periods. The syntax is: [a-z0-9\-_.]*
Binary File Name Must NOT Match: When this is selected, the regex placed in the Binary File Name Regex field indicates that the characters are not allowed in the naming of a file.
Binary Regex Description: The description is shown in addition to the standard error message. This is displayed during file upload via the WYSIWYG Editor, Source Editor, and the folder structure if the uploaded content does not conform to the defined regex.
Test Regex: The Binary File Name Regex field allows the administrator to test the configured regex to make sure that it is preventing the correct characters. The name of a file can be entered here and on-screen a green checkmark or red highlighting indicates the pass or fail status for the test.
Binary File Naming Tutorial
The following provides an example for the use of Binary File Naming to restrict file names to use only lowercase letters, numbers, hyphens, underscores, or periods.
To set up the Binary File Naming regular expression:
- Navigate to Setup > Sites, hover and from the Edit menu for the site, click Site.
- In the Binary File Naming panel, enter the following regex described in the Binary File Name Regex field: [a-z0-9\-_.]*
- Complete the fields for the Binary File Naming panel as follows:
- In the Binary File Name Regex field enter: [a-z0-9\-_.]*
- Ensure that the checkbox for Binary File Name Must NOT Match is not selected.
- In Binary Regex Description, enter a user message. This example uses the text: “Use lowercase letters, numbers, hyphens, underscores, and periods only.”
- In Test Regex field, enter an example file name to test the regex syntax. In this example, a file name using lowercase letters, numbers, hyphens, underscores, and periods receives the green checkmark.
- Test by enter a name using uppercase letters and a red X indicates the error.
- After completing the necessary fields, click Create or Save.
Below are some commonly experienced messages when trying to upload a file with an incorrect naming convention. Keep in mind that the message may be slightly different depending on the site’s settings. These examples utilize the regex that was used for the tutorial that is intended to restrict file names to use only lowercase letters, numbers, hyphens, underscores, or periods: [a-z0-9\._-]*
There are three types of available upload options when uploading from the file structure: Standard, Upload and Edit, and Zip Import.
When performing a standard Upload, if the file name contains illegal characters, the upload is disallowed and the error is shown in red. The description configured with the Binary Regex Description field is also shown.
To replicate the error:
- Navigate to the Pages list view where the binary is to be uploaded.
- Click the Upload icon.
- Drag a file with uppercase characters in the file name to upload it.
- Click Start Upload.
- Note the error message.
- Click Rename & Retry, remove the file from the modal by hovering over the file name and clicking Rename, renaming the file in your computer file browser, and upload it again.
- Click Start Upload to upload the file.
The second type of upload is Zip Import.
If illegal characters exist in the file name of a file or files, the warning message is shown in the Zip Selection section area.
Users can navigate to any file containing illegal characters, and correct the errors by clicking on the file name and updating it to meet the necessary criteria.
The Extract button is dimmed until all file naming issues are resolved.
Upload WYSIWYG Editor
When a regex has been defined for binary file naming to restrict file names to a specific file naming convention, this functionality is also used by the Insert/Edit Image feature of the WYSIWYG Editor.
If attempting to rename a file from the Pages list view, any attempted rename that does not match the regex will trigger an error message like the one below.