Reputation: 7970
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
Upvotes: 1
Views: 542
Reputation: 58004
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!
Upvotes: 1