Git Product home page Git Product logo

Comments (5)

aleksandar-cloudinary avatar aleksandar-cloudinary commented on September 22, 2024

Hi @VaelVictus,

Thanks for your post.

It looks like you're inspecting the returned object which contains the entire response, hence why you are getting back headers etc. The JSON sample response from the documentation is just the response body for a direct API call (e.g. via cURL) - but when using the SDKs, they return an object wrapping the entire response.

The actual upload response you'll receive will match the documentation for successful requests and ones that are not 'async' in which case you'll get a 'Pending' response. Therefore, if you capture the response for a successful upload in a variable and you try to access the relevant returned fields like the sample response lists, like public_id or secure_url, then you should be able to do so. For example, you could try:

$res = $cloudinary->upload($file_name, ['upload_preset' => 'my_preset']);
echo $res["public_id"] . "\n";

from cloudinary_php.

VaelVictus avatar VaelVictus commented on September 22, 2024

Thanks for the quick reply Aleksandar, I'm happy to say I got it working as you described! I wouldn't have expected PHP to work this way, but there it is.

$info = $cloudinary->upload($file_name, ['upload_preset' => 'cow_preset']);
echo $info['url'];

If you don't mind, I'm curious about how it returns the 'url' index if it's not visible when eg: dump()ing it in Laravel; maybe my understanding of PHP's OOP is limited.

from cloudinary_php.

aleksandar-cloudinary avatar aleksandar-cloudinary commented on September 22, 2024

You're welcome @VaelVictus.

Do you have a copy of the entire object you're dumping? I ask because the "url" and all other sample response fields should be in the returned object.

When you try to access a field like "url" or "public_id" it'll look it up under the "storage" ArrayObject where they will be stored.

If you want to access the "headers" part of the response you could get them returned by running: $info->headers

from cloudinary_php.

VaelVictus avatar VaelVictus commented on September 22, 2024

Ah, I appreciate the explanation. When I dumped it, I saw storage but tried to access it as if it were a public index on the returned object, not knowing it's something built into PHP and I simply had to access it without the index.

from cloudinary_php.

snetts avatar snetts commented on September 22, 2024

Just to follow up on this issue, on the searchApi() the results returned are as follows, not what is expected based on the documentation:

Cloudinary\Api\ApiResponse {#454 ▼ +rateLimitResetAt: 1657566000 +rateLimitAllowed: 500 +rateLimitRemaining: 485 +headers: array:15 [▶] flag::STD_PROP_LIST: false flag::ARRAY_AS_PROPS: false iteratorClass: "ArrayIterator" }

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.