Created
May 13, 2020 09:57
-
-
Save piersolenski/4fab8813a1580fbf654b2637f401d11a to your computer and use it in GitHub Desktop.
Cloudinary Account Migration
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
const request = require("request-promise"); | |
const cloudinary = require("cloudinary"); | |
const config = { | |
from: { | |
cloud_name: "", | |
api_key: "", | |
api_secret: "", | |
}, | |
to: { | |
cloud_name: "", | |
api_key: "", | |
api_secret: "", | |
}, | |
}; | |
async function migrate(config) { | |
const { cloud_name, api_key, api_secret } = config.from; | |
cloudinary.v2.config(config.to); | |
const res = await request( | |
`https://${api_key}:${api_secret}@api.cloudinary.com/v1_1/${cloud_name}/resources/video/?max_results=200` | |
); | |
const { resources } = JSON.parse(res); | |
resources.forEach((resource) => { | |
const { url, public_id, resource_type } = resource; | |
cloudinary.v2.uploader.upload(url, { public_id, resource_type }, () => | |
console.log(`Uploaded ${public_id}!`) | |
); | |
}); | |
} | |
migrate(config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment