5

I am working on creating a databricks notebook template with company logo. Using the below code to display image is throwing error.

Code:

%md
<img src ='/test/image/MyImage.jpg'>

Error:

HTTP ERROR 403: Invalid or missing CSRF token

Please guide me.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
ITHelpGuy
  • 969
  • 1
  • 15
  • 34
  • 1
    Try this `
    My Company
    ` When data lake storage path is given for the image source it doesn't work. But, when the image source is replaced with `http://mycompany.com/image/MyImage.jpg` http file path it works.
    – paone Jul 20 '21 at 18:16

2 Answers2

13

You either need to store image somewhere, and refer to it as a full URL, for example, you can refer your company site.

Another way is to upload file to the /FileStore directory on DBFS, and then you can refer to it using the /files/ URL, that is supported in both HTML and Markdown (see docs):

%md
![my_test_image](files/image.jpg)

You can upload image using databricks-cli, or via UI (if you have DBFS File Browser enabled). (Another option is the DBFS REST API, but it's cumbersome)

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
1

Databricks uses Markdown language. After uploading your file to Databricks notebook, you can simply use:

%md 
<img src="files/my/path/to/image.png" alt="drawing"  width="1000"/>

You can use other image properties (like width and height) to adjust your image.

Enayat
  • 3,904
  • 1
  • 33
  • 47