Send base64 File using rest_command

I need to send an image file using rest_command with application/json data payload.

here the data should send:

{
    "url":"url of the restful api",
    "authorization":"auth bearer for the API",
    "to":"phone number",
    "type":"media", 
    "file": {
        "name": "filename.jpg",
        "data": "base64 encoded jpg file",
        "mimetype": "image/jpg"
        }, 
    "text": "text to send"
}

I already made a rest_command in configuration.yaml like this:

send_snapshot:
    url: '{{url}}'
    method: POST
    headers:
       authorization: '{{authorization}}'
    content_type:  'application/json; charset=utf-8'
    payload: '{"type":"{{ type }}","text":"{{ text }}","file": {"name": "{{ name }}", "data": "{{ data }}", "mimetype": "{{ mimetype }}"},"to":"{{ to }}"}'

how should I make the script file, if i want to send file on /config/www/tmp/snapshot.jpg
and encoded to bas64 before sending using rest_command.

Thank you

Hey there, did you ever find out a solution to this? I’m looking to encode a local .jpg to base64, and then pass it into a .json to HTTP POST to another API.

I have the same problem, did you ever solve this?

Did this ever get solved?

Another thread suggested a sensor-based approach for encoding base64, but they couldn’t get it to work either.

Have you tried this?