Giter Site home page Giter Site logo

Comments (3)

const-cloudinary avatar const-cloudinary commented on July 28, 2024

Hello @holtkamp .

The goal of the extension setter is to replace/set the extension of the file, no matter what it was before.

In some cases it's hard to know whether it is a file extension or just a part of the filename (like in examples you provided).

If you want to build the right URLs, you can include the desired file extension in the constructor, like:
$mediaAsset = new CloudinaryMediaAsset('myImage.1234.jpg', $cloudinaryConfiguration);
echo mediaAsset->toUrl(); //https://res.cloudinary.com/accountName/image/upload/myImage.1234.jpg
And you can further manipulate it the way you want:
$mediaAsset->setExtension('png');
echo mediaAsset->toUrl(); //https://res.cloudinary.com/accountName/image/upload/myImage.1234.png

Or you can use transformations instead, it will deliver you file in the right format:
$mediaAsset = new CloudinaryMediaAsset('myImage.1234', $cloudinaryConfiguration);
$mediaAsset->format('png');
echo mediaAsset->toUrl(); //https://res.cloudinary.com/accountName/image/upload/f_png/myImage.1234

from cloudinary_php.

holtkamp avatar holtkamp commented on July 28, 2024

Hi @const-cloudinary, thanks for the swift response.

We intentionally store the PublicIDs of uploaded assets without extension to make it format-agnostic and stimulate serving it in whatever format is required for a certain use case.

As you suggested: by appending the extension to the PublicIDs and "not setting the extension afterwards", the problem can be circumvented, thanks!

I would suggest to document this "behaviour" / guidelines for the PublicID? Something like this:

When using dots '.' in the end of a public ID, note that the 1-5 characters after the dots are parsed as being the extension of the Media asset:

- myPublicId.1      // Extension: "1"
- myPublicId.12     // Extension: "12"
- myPublicId.123    // Extension: "123"
- myPublicId.1234   // Extension: "1234"
- myPublicId.12345  // Extension: "12345"
- myPublicId.123456 // No extension

 This derived extension will get overwritten when explicitly assigning it.

from cloudinary_php.

dannyv-cloudinary avatar dannyv-cloudinary commented on July 28, 2024

Hi @holtkamp .

Thanks for the suggestion. I'll raise it to our documentation team for consideration :)

I'm going to close off this issue, but feel free to get in touch with us if you need anything further.

Thanks,
-Danny
Cloudinary Support

from cloudinary_php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.