find single assest using public_id
I want to retrieve an asset using its public_id.
Here's the code I'm currently using:
r.instance.Upload.Explicit(r.ctx, uploader.ExplicitParams{ PublicID: r.getPublicId(path), Type: "upload", ResourceType: r.getResourceType(path), })
The issue I'm facing is determining the appropriate ResourceType
to use. Is there any alternative way which can be used to retrieve asset without using ResourceType
?(If i don't use ResourceType
, it defaults to image
, which is not what I want.)
Answers
-
Hi @kkumar_gcc,
If you don't know the
type
and theresource_type
, the best option is to actually use the Search API and search for thepublic_id
. From there, you will get theresource_type
and thetype
.Have in mind that the Search API is rate-limited so it shouldn't be used like a Search engine. If this is a requirement, when you upload an asset, you will get all the information related to the asset so you should store those in your database.
Hope that helps.
Best,
Loic
0 -
Thanks for quick reply @Vdeub,
Okay, i will use
SearchApi
then.If i want to delete a resource by
PublicID
other thanimage
resource_type, i have to mention it. Can't it be done without using resource_type? (is there any alternative of it?)result, err := r.instance.Upload.Destroy(r.ctx, uploader.DestroyParams{ PublicID: r.getPublicId(f), Invalidate: api.Bool(true), }) // if i want to delete any other `type` of resource i have to add ResourceType
0 -
@kkumar_gcc no it is not slower, it is just a different API that is rate-limited.
If you want to delete an asset without specifying the
resource_type
and thetype
, you can't use the Upload API. You can do so using the Admin API `delete_resources` method passing theall
parameter as documented here.Loic
0