Check if asset exists

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Check if asset exists

nquirynen
Hey,

When loading an asset with AssetSource.getContextAsset(path, locale) it
will throw a RuntimeException if the file doesn't exist. But what if I
want to load the asset only if it exists?
Is there a method anywhere that can check if an asset exists? I could
wrap it with a try catch, but that doesn't seem a clean solution here.

Thanks,
Nathan


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Check if asset exists

nquirynen
I found a solution for my case:

AssetSource.resourceForPath("context:"+path).exists()

On 08/12/14 17:32, Nathan Quirynen wrote:

> Hey,
>
> When loading an asset with AssetSource.getContextAsset(path, locale) it
> will throw a RuntimeException if the file doesn't exist. But what if I
> want to load the asset only if it exists?
> Is there a method anywhere that can check if an asset exists? I could
> wrap it with a try catch, but that doesn't seem a clean solution here.
>
> Thanks,
> Nathan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]