cloudinary_npm icon indicating copy to clipboard operation
cloudinary_npm copied to clipboard

How to generate `https` URL with custom cname?

Open gaurav7h4p4 opened this issue 8 years ago • 2 comments

Cloudinary.url ignores option cname, unless option secure is passed with value false, in which case it generates an http URL

Example:

expect(
  Cloudinary.url('sample', { cloud_name: 'xyz', cname: 'static.example.com' })
).to.equal(
  "https://static.example.com/xyz/image/upload/sample"
) // fails

expect(
  Cloudinary.url('sample', { cloud_name: 'xyz', cname: 'static.example.com', secure: false })
).to.equal(
  "http://static.example.com/xyz/image/upload/sample"
) // passes

// Other expectations:
expect(
  Cloudinary.url('sample', { cloud_name: 'xyz', cname: 'static.example.com', private_cdn: true })
).to.equal(
  "https://static.example.com/image/upload/sample"
)

Might need to change this condition: https://github.com/cloudinary/cloudinary_npm/blame/master/lib/utils/index.js#L928

gaurav7h4p4 avatar Dec 04 '18 14:12 gaurav7h4p4

If you have a cname that is defined through us then to generate a secure URL with your domain should be defined as the following

expect(
  Cloudinary.url('sample', { cloud_name: 'xyz', secure: true,  secure_distribution: <cname>})
).to.equal(
  "https://static.example.com/xyz/image/upload/sample"
) 

strausr avatar Dec 10 '18 10:12 strausr

Nice! I had missed the secure_distribution option, but I found it in docs after searching. Closing the issue

gaurav7h4p4 avatar Dec 11 '18 10:12 gaurav7h4p4