How to load a stl from URL?

Hello developers,

As the topic, how to load a stl from URL(http://www.csmmg.com/pikachu.stl);

loader.load( “http://www.csmmg.com/pikachu.stl”, function ( geometry ) {

} );

Chrome consoled error:

Access to XMLHttpRequest at ‘http://www.csmmg.com/pikachu.stl’ from origin ‘http://192.168.1.163:8081’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

You must use either your own, properly configured server, or a host that allows you to fetch assets via HTTP requests. Here’s a bit more discussion about CORS - long story short, your requests are blocked by the server because you’re not allowed to fetch this models.

Alternatively, you can import assets locally and ship them along with your app.

Thank dude.
Acturally, I konw about the CORS. My main question point is that it is correct if I use the url instead of the local asset files

Normally we use :

loader.load( ‘…/models/stl/…stl’, function ( geometry ) {
currentObj = geometry;
$( “#loading_data” ).hide();
} );

Yes, 100%.

1 Like

Thanks, I just tried this locally by running a different server to load URL stl. It works.

Server doesn’t block the request, the deny of service is initiated by your browser.

Another option: if you have access to CGI, ask server to fetch the file.

Select File > Import. In the Import dialog box that opens, navigate to the STL file that you want to import and select it. Windows Only (Optional) - Select STereoLithography Files (. stl) from the file type drop-down list and then click the Options button.
Tellthebell

1 Like

TIL stl == stereo lithography :smiley: