Get local files by masquerading as remote location
P粉549986089
2023-08-31 20:07:20
<p>I'm writing a Vue JS frontend served by a C# webapi application. Webapi is required to save the image to the E: drive folder on your machine and provide a src link for UI consumption. </p>
<p>Everything is fine, but now I want to test while running locally (and I don't have access to the E: drive). The problem is: I can save the images to the C: drive, but (for obvious reasons), when I try to display them, the UI browser says "Loading of local resources is not allowed". </p>
<p>Is the only solution to create some kind of remote hosting? Or is it possible to "fake" a remote blob target when the file is actually stored locally? Like Javascript's URL.createObjectURL method, but in a webapi? </p>
If you have access to the source code of the API, you may be able to build and run it locally, taking into account that it may require some environment variables that you do not have stored on your local machine and require some configuration to be able to run it locally run outside of a production environment.
If you are able to do this, then you need to update the domain name of the API in the front-end API constants (e.g. update http://{APIDOMAIN}/your/route to http://localhost:5000/your/ route) for testing locally.
Okay, NetMage's suggestion of creating a virtual IIS directory worked!
You can create a virtual directory for your running IIS application that points to a local folder.
<sites>
section in the configuration file