1

How might i take the output from a pipe and use curl to post that as a file?

E.g. the following workds

curl -F 'file=@data/test.csv' -F 'filename=test.csv' https://mydomain@apikey=secret

I'd like to get the file contents from a pipe instead but I can't quite figure out how to specify it as a file input. My first guess is -F 'file=@-' but that's not quite right.

cat data/test.csv | curl -F 'file=@-' -F 'filename=test.csv' https://mydomain@apikey=secret

(Here cat is just a substitute for a more complex sequence of events that would get the data)

Update The following works:

cat test/data/test.csv  | curl -XPOST  -H 'Content-Type:multipart/form-data' --form 'file=@-;filename=test.csv' $url
4
  • 1
    How is it "not quite right" ? Commented Mar 26, 2021 at 7:00
  • @DanielStenberg The server was complaining that req.file didn't exist (Node/Express). Hacking further adding the arguments -XPOST -H 'Content-Type:multipart/form-data' seemed to attach the data as the server expected Commented Mar 26, 2021 at 16:54
  • 1
    If you use --trace-ascii - you'll see that curl already use that Content-Type by default (and -XPOST doesn't help either). It was rather your fixed -F option that did the trick. Commented Mar 26, 2021 at 17:01
  • @DanielStenberg Very helpful. Please post your comment as the answer so I can mark as such. Commented Mar 29, 2021 at 2:52

1 Answer 1

1

If you add --trace-ascii - to the command line you'll see that curl already uses that Content-Type by default (and -XPOST doesn't help either). It was rather your fixed -F option that did the trick!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.