Send File Contents with Curl

Snippet

Testing out new API endpoints, and want to use curl to do it, use the --data-binary and @filename syntax.

This sends the file IN the body.

# use the --data-binary to leave newlines intact, saw with images
curl --data-binary "@/path/to/filename" https://api.example.com/posts
 
# If you really need newlines stripped (eh?), use --data
curl --data "@/path/to/file" https://api.example.com/posts