cloudinary / cloudinary_js

Cloudinary JavaScript library
MIT License
328 stars 224 forks source link

How to use the Cloudinary Client Side JavaScript Library with Cloudinary Media Optimizer? #269

Closed awa-nc closed 3 years ago

awa-nc commented 3 years ago

Feature request for Cloudinary JS SDK

Media Optimizer support or documentation on how to use with Media Optimizer: https://cloudinary.com/documentation/media_optimizer

Explain your use case

Migration from fetch to Media Optimizer

Describe the problem you’re trying to solve

I would like to use the Cloudinary Client Side JavaScript Library to generate Media Optimizer delivery URL's like https://demo-mo-docs.mo.cloudinary.net/cld-advanced-concepts/assets/images/shoes.jpg

Do you have a proposed solution?

No

d-mendoza commented 3 years ago

The Cloudinary config object can be configurable based on the values here. In JS you can do this:

var cl = new cloudinary.Cloudinary({cloud_name: "<cloudname>", secure: true, cname: "<cloudname>.mo.cloudinary.net", secure_distribution: "<cloudname>.mo.cloudinary.net", private_cdn: true});

Be sure to replace <cloudname> with your own cloud.

awa-nc commented 3 years ago

Thanks for the suggestion. Unfortunately, I could not get it to work. I ended up using new Transformation(...).serialize() to construct the tx query parameter that I tagged onto the Image Optimizer URL manually.