How to Empty a Folder Using Cloudinary Go SDK?

Options
kkumar_gcc
kkumar_gcc Member Posts: 3
edited August 2023 in Digital Asset Management

I encountered an issue when trying to delete a folder, as it showed an error that the folder was not empty. To address this, I found a solution using DeleteAssetsByPrefix method. However, the folder might contain various types of assets such as images, videos, or raw files. To handle this, I attempted to delete each asset type individually, which resolved the problem but resulted in three separate requests to delete assets. Is there a way to perform this task more efficiently with a single request? Here's my current code in Go:

assetTypes := []api.AssetType{api.Image, api.Video, api.File}

for _, assetType := range assetTypes {
    _, err := r.instance.Admin.DeleteAssetsByPrefix(r.ctx, admin.DeleteAssetsByPrefixParams{
        Prefix:    []string{validPath(directory)},
        AssetType: assetType,
    })

    if err != nil {
        return err
    }
}


Tagged:

Comments

  • Tamara
    Tamara Member, Cloudinary Staff Posts: 110
    Options

    Hi there,

    I would like to apologize for any confusion caused. Upon further investigation, our current API does not support deleting all three asset types (images, videos, and raw files) in a single API call. This limitation is inherent in our system at the moment.

    Once again, I apologize for any inconvenience this may have caused. Please let me know if you have any questions.

    Best regards,

    Tamara