如何在Cloudinary中移动图像



使用fetch方法,我试图将上传的图像移动到同一Cloudinary帐户内的另一个文件夹中。

我正在尝试使用以下代码移动图像:

const CLOUDINARY_URL = `https://api.cloudinary.com/v1_1/CLOUD_NAME/image/rename`;
const api_key = ******;
const image = {
...image,
url: 'the full url of the image',
public_id: 'the public id of the image'
}
const to_public_id = 'the new folder/name to where it should move to'
let formData = new FormData();
formData.append("api_key", api_key);
formData.append("from_public_id", image.public_id);
formData.append("to_public_id", to_public_id);
formData.append("signature", "NOT SURE WHAT TO PUT HERE");
const res = await fetch(CLOUDINARY_URL, {
method: "POST",
body: formData,
});

不知怎么的,这导致了CORS错误,显示了这个错误:

{"error":{"message":"Unknown API key "}}

我做错了什么?

如何获取/设置签名?

使用REST API需要签名以确保调用是有效的请求。

对于您的案例,您需要创建一个手动签名。您可以在此处关注Cloudinary的文档:

https://cloudinary.com/documentation/upload_images#generating_authentication_signatures

希望这能有所帮助,约翰·

最新更新