Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin that displays base64 as image #5805

Closed
replacementAI opened this issue Feb 3, 2024 · 3 comments
Closed

Plugin that displays base64 as image #5805

replacementAI opened this issue Feb 3, 2024 · 3 comments

Comments

@replacementAI
Copy link

I'm trying to code a plugin that is a custom visualization type, that will convert any matching base64 fields into images, but I am having trouble finding similar examples and documentation on how to code such a thing. Has anyone ever done this before, or can anyone offer some pointers? Thanks

@replacementAI replacementAI changed the title Plugin displays base64 as image Plugin that displays base64 as image Feb 3, 2024
@AMoo-Miki
Copy link
Collaborator

@replacementAI I don't know of a plugin that does that specifically but you would get a lot more eyes on this issue if you post about it on https://forum.opensearch.org.

@AMoo-Miki
Copy link
Collaborator

@replacementAI I am not sure if this will help you or not but if you will be having only one type of image encoded in base64, you can use them without a plugin. I will add an example in a few minutes.

@AMoo-Miki
Copy link
Collaborator

// Create an index
PUT /base64

// Set the mapping up to be keyword so I can use it in aggregations; text would work otherwise
PUT /base64/_mapping
{
  "properties": {
    "image": {
      "type": "keyword"
    }
  }
}

// Add some images
POST /base64/_doc 
{
  "image": "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNCAxNCIgaGVpZ2h0PSIxNCI+PHBhdGggZmlsbD0iI0M5MDAwMCIgZD0iTTEgNmgxMnYySDF6Ii8+PC9zdmc+"
}


POST /base64/_doc 
{
  "image": "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNCAxNCIgaGVpZ2h0PSIxNCI+PHBhdGggZmlsbD0iIzE4QjI0QiIgZD0iTTEzIDZIOFYxSDZ2NUgxdjJoNXY1aDJWOGg1eiIvPjwvc3ZnPg=="
}

The I created an index pattern for base64 (my index). I edited the image field by:

  1. setting "format" as Url
  2. setting "type" as Image
  3. setting "URL Template" to data:image/svg+xml;base64,{{value}}

My images are SVGs and the "URL Template" matches the data-URIs for SVG images.

I then created a Data Table visualization and the images showed fine. However, Area and Bar visualizations were adamant to use the text and I don't think they are hooked to interpret the format correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants