【问题标题】:Cloudinary authorization with direct uploadCloudinary 授权直接上传
【发布时间】:2014-01-19 04:40:16
【问题描述】:

我为 cloudinary 创建了一个有效的客户端上传脚本。上传的重要部分:

<?php
    $cloudName = "...";
    $apiKey = "...";
    $time = time();
    $apiSecret = "...";
    $fileName = "...";
?>              
<form action="https://api.cloudinary.com/v1_1/<?php echo $cloudName;?>/image/upload" method="post" enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file"><br>
    <input type="hidden" name="signature" value="<?php echo sha1('public_id='.$fileName.'&timestamp='.$time.$apiSecret);?>" />
    <input type="hidden" name="api_key" value="<?php echo $apiKey; ?>"/>
    <input type="hidden" name="timestamp" value="<?php echo $time; ?>" />
    <input type="hidden" name="public_id" value="<?php echo $fileName; ?>" />
    <input type="submit" name="submit" value="Submit">
</form>

现在我想为上传添加一个转换,所以上传在存储之前进行转换(以节省存储空间)。

我尝试添加以下代码(其中 resize 是我在我的 cloudinary 帐户中创建的转换)。

<input type="hidden" name="transformation" value="resize" />

但带有转换字段的请求会导致 401 未授权 错误。我想我必须对签名做点什么,但是什么?

【问题讨论】:

    标签: php html cloudinary


    【解决方案1】:

    您可以使用cloudinary PHP client library 中的 cl_form_tag 来构建包含所有输入标签的表单。但是,您可能希望使用 jQuery 直接上传,它可以让您更好地控制并且在 UI 方面更可定制。见here。如果由于某种原因无法使用 PHP 客户端库,则代码中有两个问题:

    1. 可以通过在其前面加上 t_ 来使用命名转换。所以transformation字段的值应该是t_resize。
    2. 需要将转换参数添加到签名中。请注意,参数名称在签名时需要按字母顺序排列。

    【讨论】:

    • 谢谢!我将 t_ 添加到转换中,并按字母顺序将其添加到签名中,它现在可以工作了!
    猜你喜欢
    • 2013-06-24
    • 2014-10-21
    • 2017-08-30
    • 2017-05-10
    • 2013-08-04
    • 2015-08-26
    • 2016-04-07
    • 2023-03-09
    • 2014-08-02
    相关资源
    最近更新 更多