Search code examples
databricksazure-databricksazure-data-lake-gen2

Display image in Databricks notebook error


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.


Solution

  • 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)