GithubHelp home page GithubHelp logo

Comments (5)

cloudinaraz avatar cloudinaraz commented on August 15, 2024

Hey @jjdiaz, the Admin API and the Upload API authentications are performed differently. While upload API indeed consists of a signature parameter, the Admin API uses Basic Authentication so the SDK doesn't generate the signature similar to the Upload API methods.

In general, special characters in the public_id should be encoded when making API requests, so can you please try and encode commas will be replaced with %2C and let me know if that solves the issue for you?

from cloudinary_php.

jjdiaz avatar jjdiaz commented on August 15, 2024

Hi, Clodinaraz.
I had already tried using urlencode without success. Please check this code snippet:

        try{
            $publicId= "Advertisements/manolito,comas";
            $encodedPublicId = urlencode($publicId);

            $result = $this->api->uploadApi()->updateMetadata(['act_test' => 'any value'], [$publicId]);
            dump($result);

        }catch (\Exception $e){
            dump($e);
        }

The result is:

Invalid Signature 43fd0c90297c7b90718923e793c7deea447e928f. String to sign - 'metadata=act_test=34343422234&public_ids=Advertisements/manolito,comas&timestamp=1655739683'.

Replacing

$result = $this->api->uploadApi()->updateMetadata(['act_test' => 'any value'], [$publicId]);
by

$result = $this->api->uploadApi()->updateMetadata(['act_test' => 'any value'], [$encodedPublicId ]);
No errors found but no asset affected. The dump($result) shows as follows:

]
storage: array:1 [
"public_ids" => []
]

public_ids is empty so no assets affected and no changes are made on the Cloudinary side.

Workarround:

I've rewriten the method signParameters on the class Cloudinary\Api\ApiUtils.php as follows:

public static function signParameters($parameters, $secret, $signatureAlgorithm = Utils::ALGO_SHA1)
    {
        $parameters = array_map('self::serializeSimpleApiParam', $parameters);

        ksort($parameters);

        $signatureContent = self::serializeQueryParams($parameters);

        /** jjd-Bugfix: This replacement prevents invalid signature errors when there are commas inside public_id */

        $signatureContent = str_replace("\,",",", $signatureContent);

        return Utils::sign($signatureContent, $secret, false, $signatureAlgorithm);
    }

I didn't get any errors and the asset was updated in Cloudinary BUT I think there are side effects that I'm evaluating now.

Best Regards,

from cloudinary_php.

momoip avatar momoip commented on August 15, 2024

Hi @jjdiaz,
The call for updateMetadata looks right, but since you get no error but not find any "public_ids". Please open a support ticket and provide me the cloud name and make the call and I can investigate from our log and let you know.

from cloudinary_php.

jjdiaz avatar jjdiaz commented on August 15, 2024

Hello @momoip
I just opened ticket #190154

from cloudinary_php.

aksjoshi1 avatar aksjoshi1 commented on August 15, 2024

Hi @jjdiaz
Closing this issue here. We will continue on the support ticket

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.