playcanvas / playcanvas/editor

getFileUrl returns inconsistent URL schema

Open
#665 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: assets area: launch tab area: publishing bug
Dominant language
TypeScript
Stars
1.3k
Forks
215
Avg merge
1d 29m
Merged PRs (30d)
30

Description

asset.getFileUrl() returns inconsistent URL

This issue is noted at https://forum.playcanvas.com/t/x-frame-options-deny-on-assets/23837/3

Steps to Reproduce
  1. Create a new PlayCanvas project
  2. Add an asset such as index.html
  3. Launch the project
  4. In the JavaScript console type:
pc.app.asset.findAll('index.html', 'html')[0].getFileUrl();
Result

The response is a relative URL. i.e.
/api/assets/files/Library/MyProject/index.html?id=656796

Expected Response

We should get a FQURL (fully qualified/absolute URL) as we do when publishing. i.e.
https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/HSBSlcXy/..

Workaround

Currently we can sense when the API is accessed in launcher vs published; check the domain origin, look for the debug flag, or check for the protocol, and append the origin for relative assets i.e.

var url = pc.app.asset.findAll('index.html', 'html')[0].getFileUrl();
if (url.substring(0,4) != 'http') {
   url = window.location.origin + url;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the asset.getFileUrl() entry point shown in the reproduction and inspect how it constructs URLs in the editor. Reproduce the console call with an asset such as index.html, then compare the result with the published URL behavior. Done means the method returns a fully qualified URL rather than the current relative path.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.