Skip to content

Instantly share code, notes, and snippets.

@piersolenski
Created May 13, 2020 09:57
Show Gist options
  • Save piersolenski/4fab8813a1580fbf654b2637f401d11a to your computer and use it in GitHub Desktop.
Save piersolenski/4fab8813a1580fbf654b2637f401d11a to your computer and use it in GitHub Desktop.
Cloudinary Account Migration
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