Created
November 25, 2021 14:44
-
-
Save arthurdenner/de2f1ef594d8e0c297f2c26ea408ce6f to your computer and use it in GitHub Desktop.
Parse Cloudinary URL with options
This file contains 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
const parseCloudinaryUrl = (url) => { | |
const [apiKey, apiSecret, cloudName, options] = url | |
.split(/cloudinary:\/\/(\w+):(\w+)@(\w+)\??(.*)/) | |
.filter(Boolean) | |
return { | |
apiKey, | |
apiSecret, | |
cloudName, | |
options: Object.fromEntries(new URLSearchParams(options)), | |
} | |
} | |
const CLOUDINARY_URL = 'cloudinary://apiKey:apiSecret@cloudName?uploadFolder=customFolder' | |
const uploadConfig = parseCloudinaryUrl(CLOUDINARY_URL) | |
/* | |
{ | |
apiKey: "apiKey", | |
apiSecret: "apiSecret", | |
cloudName: "cloudName", | |
options: { | |
uploadFolder: "customFolder", | |
}, | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment