2

I'm setting up a script and I want to display an image which is located outside of my static folder. My project is designed like this:

___folder
  |__ image.png
  |__ text.txt
___web
  |__static
    |__ css
    |__ js
  |__ app.py

At the moment, I just run my script app.py. I have managed to create a hyperlink to download my image from another folder using the file protocol with this:

<a href="file://///{{ image_path }}">Download </a><br>

This way works but I'm forced to right click on the hyperlink and paste it in a new window in order to download it. I'm looking for a way to just left click on it.

After that, I've tried to display this same image with:

<img src="file://///{{ image_path }}" style="width:100%;" alt="Image not found">

but it actually doesn't work even if the path works for the previous part.

I've obtained some errors, when I've inspected the page as:

Failed to load resource: the server responded with a status of 404 (NOT FOUND)

UPDATE 1

Is there a way to solve my issue by using mimetype here?


Any help or direction is highly appreciated. Thank you.

Maitresage
  • 81
  • 1
  • 10
  • Can I ask why you've used `/////` rather than `//`? – clubby789 Aug 08 '19 at 09:57
  • I think that I just need to write `///` instead of `/////` [topic where I found some help](https://stackoverflow.com/questions/18246053/how-can-i-create-a-link-to-a-local-file-on-a-locally-run-web-page) – Maitresage Aug 08 '19 at 10:09

2 Answers2

1

https://www.w3schools.com/tags/att_a_download.asp Simply add the download attribute to your <a> tag, e.g.,

<a href="file://///{{ image_path }}" download="filename.png">

The ="filename.png" is optional, you can just have download with no paramaters.

clubby789
  • 2,543
  • 4
  • 16
  • 32
  • With your method I'm still forced to paste the link in another page, by clicking on the hyperlink nothing happens. – Maitresage Aug 08 '19 at 10:08
0

This is a security exception built into Chrome. In the past you could override settings in Chrome like this. Check other topic in Stack, I can link dozens where you can find by yourself some help. You could use an intermediary page that serves the network based files for example.

You can find some help here.

Bando
  • 1,223
  • 1
  • 12
  • 31