3

I have the following controller:

public IActionResult Post([FromQuery] int Width, [FromQuery] int Height, [FromForm] IFormFile Image)

With Insomnia / Postman, I can do a post command and pass the width / height parameters in the url.

I am trying to do the same with CURL but the second parameter is not seen. In this case, height will be 0

curl -F image=@photo.jpg test/thumbnail?width=320&height=240

In that case, width will be 0

curl -F image=@photo.jpg test/thumbnail?height=240&width=320

What am I missing?

Thomas
  • 184
  • what OS/utility set are you working on? i'd start by reading the man page or equivalent for your implementation/distribution/whatever and check the --data or -d option – ivanivan May 09 '18 at 00:03
  • I'm on Mac; I tried -d "width=320" -d "height=240" but Curl told me it wasn't compatible with the multi-part post – Thomas May 09 '18 at 00:04
  • Try them together - -d "width=320&height=240" – ivanivan May 09 '18 at 00:19

2 Answers2

6

The most likely problem is that & is a special character in your macOS shell (the command-line interpreter); if left unquoted, it acts as a command separator and runs the preceding command in background. The rest (height=240) is interpreted as a second command by macOS.

So the parameter with & must be quoted, or the & itself escaped with a backslash:

"test/thumbnail?height=240&width=320"
test/thumbnail?height=240\&width=320
test/thumbnail?height=240"&"width=320
test/thumbnail?'height=240&width=320'
etc.

(? is also special in that it's a wildcard, but that's only a problem if it happens to match a real filename on the local system.)

The comments suggesting -d aren't correct. For one, they send parameters as POST payload – but the controller wants query-string (GET) parameters, which isn't the same thing at all. For another, the request can only use one format at a time – you cannot mix -F and -d in the same request.

u1686_grawity
  • 452,512
1

for Mac OS the correct one would be

curl -F image=@photo.jpg test/thumbnail?width=320**\&**height=240

In Mac, you have to escape &