我为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.'×tamp='.$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 unauthorized 错误 . 我想我必须对签名做些什么,但是什么?
1 回答
您可以使用cloudinary PHP client library中的cl_form_tag来构建包含所有输入标记的表单 . 但是,您可能希望使用jQuery直接上载,它可以提供更好的控制,并且可以更加自定义UI . 见here . 如果由于某种原因无法使用PHP客户端库,则代码中存在两个问题:
可以通过为t_加前缀来使用命名转换 . 因此,转换字段的值应为t_resize .
需要将转换参数添加到签名中 . 请注意,签名时参数名称必须按字母顺序排列 .