5 releases

0.1.4 May 25, 2023
0.1.3 Aug 24, 2021
0.1.2 Aug 16, 2021
0.1.1 Aug 13, 2021
0.1.0 Aug 8, 2021

#540 in Development tools

Download history 1/week @ 2024-02-14 4/week @ 2024-02-21 4/week @ 2024-02-28 26/week @ 2024-03-27 33/week @ 2024-04-03

59 downloads per month

GPL-3.0-or-later

26KB
58 lines

Duri

made-in-vietnam registry

CLI tool to get data URI of a file.

Logo

Install

Duri is written in Rust, so you can install it from crates.io:

cargo install duri

Usage

  • Read from file path:

    duri image.png
    
  • Read from standard input:

    echo image.png | duri -
    
  • To see more option, run with --help:

    duri --help
    

Use cases

Assume that you need to upload file to a RESTful HTTP API. The HTTP API may require posted data to be JSON string and the file content to be in form of base64-encoded data URI.

You can combine Duri with jo to build JSON, like:

jo -d. file.name=image.png file.content=$(duri image.png)

then pass to a CLI HTTP client, like HTTPie:

jo -d. file.name=image.png file.content=$(duri image.png) | http example-api.vn/ekyc/

The duri + jo combo will generate a JSON like

{
  "file": {
    "name": "image.png",
    "content": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAABI2..."
  }
}

The string is passed to HTTPie via standard input and HTTPie will build a POST request with that JSON data.

Note that, if your HTTP API requires file to be in plain base64 string, not beginning with data:xxx, you don't need Duri. In that case, just use jo alone, with its % modifier:

jo -d. file.name=image.png file.content=%image.png | http example-api.vn/ekyc/

Credit

Dependencies

~8–19MB
~239K SLoC