Home Explore Blog CI



nushell

5th chunk of `cookbook/http.md`
44dec3b5ba800ef5fbfd07b87c4a3c889b60c1ae7bd3df380000000100000e47
# => │         │ ╭─────────────┬────────────╮                                                                          │
# => │ form    │ │ description │ Small icon │                                                                          │
# => │         │ ╰─────────────┴────────────╯                                                                          │
# => │         │ ╭────────────────────────┬──────────────────────────────────────────────────────────────────────────╮ │
# => │ headers │ │ Accept                 │ */*                                                                      │ │
# => │         │ │ Accept-Encoding        │ gzip                                                                     │ │
# => │         │ │ Content-Length         │ 893                                                                      │ │
# => │         │ │ Content-Type           │ multipart/form-data; boundary=cddfac9d-e5e0-4aa3-a3df-6f9f6e570bc9       │ │
# => │         │ │ Host                   │ httpbin.org                                                              │ │
# => │         │ │ User-Agent             │ nushell                                                                  │ │
# => │         │ │ X-Amzn-Trace-Id        │ Root=1-66b28d98-549045021ddb79ab3d0eda79                                 │ │
# => │         │ ╰────────────────────────┴──────────────────────────────────────────────────────────────────────────╯ │
# => │ json    │                                                                                                       │
# => │ url     │ https://httpbin.org/post                                                                              │
# => ╰─────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────╯
```

If the file happens to be a text file, you may need to additionally convert it to binary data before sending it. This can be done using the `into binary` command.

```nu
http post https://httpbin.org/post --content-type "multipart/form-data" {
  doc: (open -r ~/Downloads/README.txt | into binary),
  description: "Documentation file"
}
# => ╭─────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
# => │ args    │ {record 0 fields}                                                                                        │
# => │ data    │                                                                                                          │

Title: Uploading Text Files as Binary Data
Summary
This section highlights that for text files, you might need to convert them to binary data using the `into binary` command before uploading them via `http post` with `multipart/form-data`. An example demonstrates uploading a README.txt file, emphasizing the conversion to binary for proper handling.