Skip to content

ImageOverlay does not accept data uris as valid and treats them as file name instead #1427

Closed
@Kirill888

Description

@Kirill888

Describe the bug

Supplying a data URI as image parameter to ImageOverlay raise FileNotFound error.

To Reproduce

from folium.raster_layers import ImageOverlay
img_url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
ImageOverlay(img_url, bounds=[[0,0], [1,1]])

Expected behavior
Image url is passed into output as is.

Environment (please complete the following information):

  • Browser firefox
  • Jupyter Notebook or html files -- jupyter lab?
  • Python version 3.8
  • folium version 0.11.0
  • branca version 0.3.1

Possible solutions

Problem is due to data scheme being absent from the allow list here:

_VALID_URLS = set(uses_relative + uses_netloc + uses_params)
_VALID_URLS.discard('')

Patching it at run time solves the problem, i.e. this works as expected

import folium.utilities
folium.utilities._VALID_URLS.add('data')

from folium.raster_layers import ImageOverlay
img_url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
ImageOverlay(img_url, bounds=[[0,0], [1,1]])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions