Last active
January 31, 2017 11:08
-
-
Save lusentis/e68a81c5e0d5340bf059d386cf46f5df to your computer and use it in GitHub Desktop.
parses an Amazon S3 URL and returns bucket, region and key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseS3URL(url) { | |
const tokens = /^https:\/\/([\w\d-]+)\.s3(-(\w\w-\w+-\d))?\.amazonaws\.com\/(.*?)((#|%23).*)?$/.exec( | |
url | |
); | |
if (!tokens) { | |
return false; | |
} | |
const [, bucket, , region = 'us-east-1', key] = tokens; | |
return { bucket, region, key }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment