Comments (5)
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.
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.
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.
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.
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)
- PHP 8.1 support HOT 5
- Migrate from Travis to GitHub actions HOT 2
- Add PHPStan HOT 1
- Wrong CLOUDINARY_URL HOT 3
- Missing a way to easily request every asset type HOT 18
- Deprecated: fopen(): Passing null to parameter #3 ($use_include_path) of type bool is deprecated (php 8.1) HOT 1
- Update access mode method not available in SDK HOT 10
- [2.7.1] Why separate package and failure on composer-require-checker HOT 1
- Fatal Error on PHP 7.4 HOT 2
- Bad signature when public id contains commas HOT 5
- Error using defaultvalues in class SetMetadataField HOT 1
- Incorrect URL generated when Public ID of MediaAsset ends with dot + 1-5 characters HOT 3
- ${var} -> {$var} for PHP 8.2 compatibility in version 1.x HOT 5
- Deprecations on PHP 8.2 HOT 1
- Call to undefined function GuzzleHttp\Promise\promise_for() HOT 3
- Get rid of `teapot-php/status-code` dependency HOT 9
- Drop Guzzle requirement and replace with any PSR-18 HttpClient
- Use named parameters instead of array in Version 3 HOT 1
- Class 'Cloudinary\ClassUtils' not found HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloudinary_php.