We convert filename to a valid format. If your filename contains unacceptable symbols, they will be stripped. Correct symbols include ASCII letters, digits, the “_” symbol, and a proper file extension.
If your backend needs to know what the new filename is after the upload, check out this snippet in python.
For the client side, this Javascript function will do the same:
function cleanFileName(your_string) {
//check for empty string
if (your_string.length == 0)
return false;
var ext_re = /[^.]+$/;
// ascii letters, digits, '_' symbol are only valid characters
var replace_re = /[^\w^\d^\\_]/g;
var extension = ext_re.exec(your_string)[0];
// if filename doesn't have an extension
if (extension.length == your_string.length)
return your_string.replace(replace_re, '');
// clean root and extension
var filename_length = your_string.length;
var extension_length = extension.length;
var root_length = filename_length - extension_length - 1;
var root = your_string.substring(0, root_length);
var clean_root = root.replace(replace_re, '');
var clean_extension = extension.replace(replace_re, '');
return clean_root + '.' + clean_extension;
}