3

I have request in Insomnia. When I send it via Insomnia, no problemo. But when I generate source code for curl, it shows me this.

curl --request POST \
  --url URL \
  --header 'Authorization: bearer XXX' \
  --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
  --cookie JSESSIONID=XXX \
  --form datasetFile=@FOLDER/producthierarchyl1-1.zip

{"message":"Bad Request","logref":null,"path":null,"_embedded":{"errors":[{"message":"Required argument [Publisher datasetFile] not specified","logref":null,"path":"/datasetFile","_embedded":{},"_links":{}}]},"_links":{"self":{"href":"/data-api/public-api/v4/datasets/ingestion/","templated":false,"profile":null,"deprecation":null,"title":null,"hreflang":null,"type":null,"name":null}}}

Insomnia output is like this.

> POST PATH HTTP/2
> Host: URL
> user-agent: insomnia/2022.3.0
> cookie: JSESSIONID=XXX
> authorization: bearer XXX
> content-type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> accept: */*
> content-length: 407

* STATE: DO => DID handle 0x170404b14008; line 2077 (connection #27)
* multi changed, check CONNECT_PEND queue!
* STATE: DID => PERFORMING handle 0x170404b14008; line 2196 (connection #27)

| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="datasetFile"; filename="producthierarchyl1-1.zip"
| Content-Type: application/zip
| PK�QU�}�%+producthierarchyl1-1.csvUT  բ�b
| --X-INSOMNIA-BOUNDARY--

* We are completely uploaded and fine
* HTTP/2 found, allow multiplexing

Where is the catch?

Thanks.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
genderbee
  • 203
  • 2
  • 10
  • @DanielStenberg Wow, you are right. But I don't understand why is header problem, even Insomnia generated it with it. But thanks a lot. – genderbee Aug 19 '22 at 12:50

2 Answers2

6

Remove the --header 'content-type: multipart/form-data; boundary=---011000010111000001101001 option.

It really should not be used like this: curl manages that header and the boundary on its own so changing it should only be done in the rare event you truly want and need to fiddle around with it.

A more minor second thing: --request POST should be dropped from the command line, as it is superfluous and easily cause problems if you add --location later on.

Updated

This flaw is said to have been fixed in a later version of Insomnia

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
  • 1
    Issue was reported to Insomnia team. – genderbee Aug 19 '22 at 14:00
  • Hi @genderbee, Filipe from the Insomnia team here! This issue has been fixed in later Insomnia versions than the one you are using (2022.3.0). It was fixed in a PR in a dependency we use, https://github.com/Kong/httpsnippet/pull/227, but the dependency had been only updated to the version with the fix a few months ago. If you upgrade to latest stable (or beta) release, you should be able to use `Copy as Curl` and shouldn't have this problem. Check over at https://github.com/Kong/insomnia/releases It has since been fixed – Filipe Freire Aug 19 '22 at 14:26
1

For any folks bumping into this issue again, this answer correctly explains the reason for the problem.

Fortunately this should only be reproducible in versions 2022.3.0 and older versions of Insomnia.

If you use the latest one, 2022.5.1, the generated curl will no longer have this problem, example of a multipart request generated:

curl --request GET \
  --url http://mockbin.org/request/anything \
  --header 'Content-Type: multipart/form-data' \
  --form test=test \
  --form test=@/Users/yourUserName/Desktop/somefile.txt
Filipe Freire
  • 823
  • 7
  • 21
  • 1
    a multipart `GET`, really? and also, that `content-type:` provided header is still superfluous – Daniel Stenberg Aug 19 '22 at 14:43
  • It was what I was using purely for example with mockbin.org. As for the `content-type` header, might be something we can improve. EDIT: actually, taking into account all of what you mentioned, yeah, there's still a handful of things we can remove and improve, will try to follow up on this. Thank you Daniel! – Filipe Freire Aug 19 '22 at 15:14
  • 1
    @FilipeFreire Hi Fiilpe, Kristofer Huffman contacted me, I tried latest version, `header` is without `boundary`, but header still present in generated code. – genderbee Aug 25 '22 at 12:41