Skip to content
Advertisement

Error when trying to display an image saved in a computer file

I am developing an application which allows me to bring some files saved from another server for that I have a code made in Asp.net which I consume with Javascript to bring the image, but when I get the image to show it, the following generates me error, Not allowed to load local resource: file: /// C: /Users/usuario/Desktop/imagenes/prfil/descarga.png, but when I copy the same link in the browser if it brings me the image:
This is my code .net:

JavaScript

And this my code JavaScript:

JavaScript

Advertisement

Answer

Browsers use the local file:// protocol to load local files, which is only allowed for local calls. Same thing with HTTP protocol; it won’t work to use this protocol followed by the full path of a local file. Yet, you have at least two options here. You either provide a public folder within your application’s root directory, where you can access the file using a relative URI, which is the safer way of doing it. Another possible approach is to return a file instead of a path. For this one, you may do something like this:

Javascript

JavaScript

C#

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement