I find myself in a specific situation:
- Working with a Laravel 8 application.
- My users upload STL files, which are stored in the
storage/app/users/{userid}
directory. - These STL files are private and not accessible to everyone as they are not located in the public folder.
Now, I am attempting to access these private STL files using JavaScript in order to display them in my Three.js scene for viewing.
However, when trying to retrieve the file path from the database before and passing it to the Three.js STLLoader function like this:
import * as THREE from 'three';
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';
// {...}
let THREE_loader = new STLLoader();
let THREE_geometry;
THREE_loader.load(filePath, function (geometry) {
THREE_geometry = geometry;
// {...}
});
I encountered the 404 error message every time I attempt it, since the provided path is relative to the web root and incorrect!
[Error] Failed to load resource: the server responded with a status of 404 (Not Found)
So, my question now is:
Is there a way to overcome this obstacle? How can I access private files (not in the public folder) through JavaScript in my Laravel 8 application? There must be a solution, right?
Some other solutions I considered:
- Directly storing the files in the database -> files may be too large?!
- Storing an "secure" encrypted file path within the public(!) directory in the database -> not secure enough?!
Both of these "solutions" are definitely not ideal for me!
If anyone could provide guidance or direction on this matter, I would greatly appreciate it! 🤔
Warm regards, Leon