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=240In that case, width will be 0
curl -F image=@photo.jpg test/thumbnail?height=240&width=320What am I missing?
32 Answers
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.
for Mac OS the correct one would be
curl -F image=@photo.jpg test/thumbnail?width=320**\&**height=240In Mac, you have to escape &