How do you know if a file exists

I want to check if the file exists when I jump to the url. How do I do that?

Hi @chuxinhao,

Is the file an asset in your Playcanvas project?

If that’s the case you can more simply do this (make sure your asset names are unique):

if( this.app.assets.find('MyHtmlFile.html') !== null){

   // asset exists
}

If you are asking how to check if an external url exists, you need to make a GET request and check the result. Playcanvas provides an easy to use http requests class:

https://developer.playcanvas.com/en/api/pc.Http.html

Thank you for your reply. I want to check whether the external URL exists.Use the Get
https://developer.playcanvas.com/en/api/pc.Http.html#get

1 Like