我想使用node.js框架从Cloudinary存储中删除视频类型的资产。 此代码可以正常删除图像类型的资源,但不能删除视频类型的资源。
我尝试将
destroy
函数与资产的 public id
一起使用。
const deleteFilesFromCloud = async function (filePublicId) {
try {
const response = await cloudinary.uploader
.destroy(filePublicId);
return response;
} catch (error) {
console.log('Error in deleting file from cloud');
return null;
}
}
在 Cloudinary 中,资产不仅由
public_id
标识,而且仅当 public_id
与 resource_type
(例如“图像”、“视频”、“原始”)和 type
组合时才可标识。 (“上传”、“私有”、“经过身份验证”等)。您可以拥有具有完全相同的 public_id
的图像和视频,但它们将被视为不同的资产,因为 resource_type
不同。您至少需要在数据库中存储 public_id
、resource_type
和 type
,因为这三部分数据将允许您通过 API 引用您的 Cloudinary 帐户中的任何资产。
有鉴于此,您需要将
resource_type: "video"
添加到您的 destroy()
调用中,以便 Cloudinary 可以找到您要引用的资产。
const response = await cloudinary.uploader.destroy(filePublicId, { resource_type: "video" });
参考资料: