# Embed local image in Dash app with HTTP?

**URL:** <https://discourse.julialang.org/t/embed-local-image-in-dash-app-with-http/51004>\
**Category:** Web Stack\
**Created:** [November 30, 2020, 6:35pm UTC](https://discourse.julialang.org/t/embed-local-image-in-dash-app-with-http/51004 "2020-11-30T18:35:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [November 30, 2020, 6:35pm UTC](https://discourse.julialang.org/t/embed-local-image-in-dash-app-with-http/51004/1 "2020-11-30T18:35:17Z")

</div>

I am developing a Dash.jl app and discovered that I cannot embed local pictures. One [workaround](https://github.com/plotly/dash/issues/71) I found is to somehow host images on a local server in order to display them, but I have no idea how to do that in Julia.

My idea was to serve a small html page with the image, and embed that in the Dash app by using it’s url, but I still can’t get the image to be displayed with HTTP. Here is a small example:

```julia
using HTTP

HTTP.serve("127.0.0.1", 8080) do request::HTTP.Request
   try
       return HTTP.Response("""<html>
<body>

<button type="button">Click Me!</button>
<h1>Some title</h1>

<img src=C:\\Users\\cioarca\\Documents\\x.png width="300" height="200">

</body>
</html>""")
   catch e
       return HTTP.Response(404, "Error: $e")
   end
end

```

Any suggestion is highly appreciated.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [November 30, 2020, 6:47pm UTC](https://discourse.julialang.org/t/embed-local-image-in-dash-app-with-http/51004/2 "2020-11-30T18:47:49Z")

</div>

The easiest way is probably to just embed them as base64-encoded data:

```julia
using Dash, DashHtmlComponents, Base64
app = dash()
app.layout = 
    html_div([
        html_h1("embedded image", style=(textAlign = "center",)),
        html_img(src="data:image/png;base64,$(open(base64encode, "/path/to/file.png"))"),
    ])
run_server(app, "0.0.0.0", 8080)

```

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [November 30, 2020, 6:49pm UTC](https://discourse.julialang.org/t/embed-local-image-in-dash-app-with-http/51004/3 "2020-11-30T18:49:38Z")

</div>

Browsers do not usually allow a web page served from a server to also access local files. Imagine the security vulnerability when hitting some arbitrary web page that reads your private files. Your server must also serve the image. I don’t know about Dash, so I can’t suggest how you would do that.

---

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [November 30, 2020, 7:19pm UTC](https://discourse.julialang.org/t/embed-local-image-in-dash-app-with-http/51004/4 "2020-11-30T19:19:14Z")

</div>

Thank you very much! It worked!

 ![dash](https://global.discourse-cdn.com/julialang/original/3X/b/b/bb2a396503d51081d63eec38d0f4112e7428c410.png)
