简体   繁体   English

如何在 php 中读取 cloudinary API 响应对象以获取上传后的安全 url

[英]How to read cloudinary API Response Object in php to get the secure url after upload

I am trying to upload to cloudinary through php, I tried the following code from my localhost and upload is successful and I get the response as Cloudinary APIResponse object我正在尝试通过 php 上传到 cloudinary,我从本地主机尝试了以下代码,上传成功,我得到了 Cloudinary APIResponse 对象的响应

$config = Configuration::instance();
$config->cloud->cloudName = 'cloudname';
$config->cloud->apiKey = 'apikey';
$config->cloud->apiSecret = 'secrethere';
$config->url->secure = true;

$cloudinary = new Cloudinary($config);

$resp = $cloudinary->uploadApi()->upload( './Broccoli.gif', ["use_filename" => TRUE, "unique_filename" => FALSE, "folder" => "mythumbs"] );

and the response is响应是

Cloudinary\Api\ApiResponse Object
(
    [rateLimitResetAt] => 
    [rateLimitAllowed] => 0
    [rateLimitRemaining] => 0
    [headers] => Array
        (
            [Date] => Array
                (
                    [0] => Sat, 28 May 2022 18:58:47 GMT
                )

            [Content-Type] => Array
                (
                    [0] => application/json; charset=utf-8
                )

            [Transfer-Encoding] => Array
                (
                    [0] => chunked
                )

            [Connection] => Array
                (
                    [0] => keep-alive
                )

            [Vary] => Array
                (
                    [0] => Accept-Encoding
                )

            [Status] => Array
                (
                    [0] => 200 OK
                )

            [Cache-Control] => Array
                (
                    [0] => max-age=0, private, must-revalidate
                )

            [X-XSS-Protection] => Array
                (
                    [0] => 1; mode=block
                )

            [X-Request-Id] => Array
                (
                    [0] => a57f3df3ad7ba508ac21009183adb527
                )

            [X-UA-Compatible] => Array
                (
                    [0] => IE=Edge,chrome=1
                )

            [ETag] => Array
                (
                    [0] => "38ba68cdf700d347e507b1f5e15176fe"
                )

            [Server] => Array
                (
                    [0] => cloudinary
                )

        )

    [storage:ArrayObject:private] => Array
        (
            [asset_id] => 68b431d7e07ffeca56af43062eb6da22
            [public_id] => mythumbs/Broccoli
            [version] => 1653764327
            [version_id] => ba3190f6dc801e856e8056ac0e2a8be8
            [signature] => 50974060aa15a82b8fa0e5ee6c49809d82c46189
            [width] => 600
            [height] => 600
            [format] => gif
            [resource_type] => image
            [created_at] => 2022-05-28T18:58:47Z
            [tags] => Array
                (
                )

            [pages] => 1
            [bytes] => 13349
            [type] => upload
            [etag] => fc64f57bcf6066b19f1b7d803298bc25
            [placeholder] => 
            [url] => http://res.cloudinary.com/hooshiyaa/cloudname/upload/v1653764327/mythumbs/Broccoli.gif
            [secure_url] => https://res.cloudinary.com/cloudname/image/upload/v1653764327/mythumbs/Broccoli.gif
            [folder] => mythumbs
            [original_filename] => Broccoli
            [api_key] => 
        )

)

I couldn't find any example of how to read this response object on cloudinary documentation.我在 cloudinary 文档中找不到任何有关如何阅读此响应对象的示例。 I want to retrieve the secure url and store it in db.我想检索安全 url 并将其存储在 db 中。

It seems cloudinary ApiResponse class is an extension of PHP Arrayobject, so all the methods listed here works on the response object from cloudinary.似乎 cloudinary ApiResponse 类是 PHP Arrayobject 的扩展,所以这里列出的所有方法都适用于来自 cloudinary 的响应对象。 OffestGet fetched me the secure url. OffestGet 为我获取了安全网址。 Thank You.谢谢你。

https://www.php.net/manual/en/class.arrayobject.php https://www.php.net/manual/en/class.arrayobject.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM