Skip to content

Instantly share code, notes, and snippets.

@arthurdenner
Created November 25, 2021 14:44
Show Gist options
  • Save arthurdenner/de2f1ef594d8e0c297f2c26ea408ce6f to your computer and use it in GitHub Desktop.
Save arthurdenner/de2f1ef594d8e0c297f2c26ea408ce6f to your computer and use it in GitHub Desktop.
Parse Cloudinary URL with options
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