Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing from data: URIs / MIME type inference #424

Open
antonok-edm opened this issue Oct 11, 2023 · 0 comments
Open

Importing from data: URIs / MIME type inference #424

antonok-edm opened this issue Oct 11, 2023 · 0 comments
Labels

Comments

@antonok-edm
Copy link

There isn't an obvious way to import a 3D model directly from a data: URI. I tried using LoadModelFromUrlList with the data: URI, but it failed with No importable file found.

After some experimentation, I was able to create it by manually constructing a File object, although it wasn't pretty:

const dataUrl = 'data:model/stl;base64,...';

const dataBlob = await fetch(dataUrl).then(res => res.blob());
const dataFile = new File([dataBlob], 'foo.stl');  // must manually provide correct extension

viewer.LoadModelFromFileList([dataFile]);

Some brief digging through the code suggests that the filename's extension is used to determine whether or not a model format is supported. That approach is incompatible here because data: URIs do not have filenames.

Perhaps also of interest; URL fetch responses may offer a supported MIME type despite the URL's path having a different extension, or no extension at all. I imagine it'd be useful to support cases like that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant