Skip to content

Instantly share code, notes, and snippets.

@morficus
Created December 30, 2018 01:32
Show Gist options
  • Save morficus/75298908c356b0b1871cf16f9d9a4be0 to your computer and use it in GitHub Desktop.
Save morficus/75298908c356b0b1871cf16f9d9a4be0 to your computer and use it in GitHub Desktop.
/**
* Returns a string with all S3 unsafe characters replaced with a dash (-)
* @param dirtyFileName
* @returns {*}
*/
export default function(dirtyFileName) {
// handle any special characters that might be in the file name
// ref: https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-key-guidelines
return dirtyFileName.replace(/[&$@=;:+,?^{}%`\]">~<#|]/g, '-')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment