ASP .NET Core .glb file not found whereas the file was copy

Hello

I want to import a .glb file but when I call it in JS I get an error which tell me that the file isn’t found whereas the file was copied.
Here’s my files:

wwwroot
 /-Assets
 /---Element
 /---Objects3D
 /-----hub.glb

Here, the error:

Failed to load resource: the server responded with a status of 404 ()    :44353/Assets/Objects3D/hub.glb:1

Have you an idea ?
Thank you !

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Ok so with some little investigation I was able to solve my issue, this might help you solve your problem too.

In the server side when setting the UseStaticFiles you should add some options to allow UnkownType files to be accessed.
There are two ways you can solve this. The first is especifying the type of the file that you wish to provide that way. In this case you should do it this way on you Startup.cs file, Configure function:

StaticFileOptions options = new StaticFileOptions { ContentTypeProvider = new FileExtensionContentTypeProvider() };
((FileExtensionContentTypeProvider)options.ContentTypeProvider).Mappings.Add(new KeyValuePair<string, string>(".glb", "model/gltf-buffer"));
app.UseStaticFiles(options);

The second option (and more appropriate if you have more than 1 Unkown file type) is to allow any UnkownTypeFile using a flag on the same StaticFileOptions at the same Configure function:
StaticFileOptions options = new StaticFileOptions { ContentTypeProvider = new FileExtensionContentTypeProvider() };
options.ServeUnknownFileTypes = true;
app.UseStaticFiles(options);

Also, make sure you are able to access the subdomain directories on you server. If you are not, then you should also include this in your ConfigureServices function in the Startup.cs file:
services.AddDirectoryBrowser();

As well as the line bellow on your Configure function at the same file:
app.UseFileServer(enableDirectoryBrowsing: true);

Note: This solution is for a server using .Net Core 3.1. If you are using a different version or .Net Framework there might be a different fix.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x