Vscode-restclient: Unable to send requests "multipart/form-data" that contains files

Created on 21 Feb 2019  路  6Comments  路  Source: Huachao/vscode-restclient

  • VSCode Version: 1.31.1 (user setup)
  • OS Version: Windows_NT x64 10.0.17134
  • REST Client Version: 0.21.1

Error description:
If a request with the content-type "multipart/form-data" containing a file is to be executed, the request continues endlessly and must be aborted with ctrl+alt+k. If no file is transmitted or could not be found, e.g. because the specified file name is not correct, the request works. With file, the request does not work or continues indefinitely without an error message.

Steps to Reproduce:
POST https://www.xxx.de/api/v1/xxxxx HTTP/1.1
Authorization: Bearer XXXXXXXXXXXXXXX
Content-Type: multipart/form-data; boundary=----HereGoes

------HereGoes
Content-Disposition: form-data; name="text"
Content-Type: text/plain
TEXT
TEXT
TEXT
------HereGoes
Content-Disposition: form-data; name="test"; filename="test.png"
Content-Type: image/png

< test.png
------HereGoes--

bug

Most helpful comment

Hi @Huachao,

My humble apologies, it was an error in my request composition that was causing the problem. I'll document it here so that others hopefully do not fall into the same trap.

The RFC on multipart/form (https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html) states the BNF form of the boundary to be:

boundary := 0*69 bcharsnospace
delimiter := CRLF "--" boundary
close-delimiter := delimiter "--"

In my example above, I had the same boundary and delimiter values (i.e. delimiter should have an additional -- before it).

A working request: (Note the boundary= value in comparison with my non-working version)

POST /v1/myendpoint HTTP/1.1
Host: localhost:12000
Accept: application/json
Content-Type: multipart/form-data; boundary=MyBoundary
Authorization: Bearer {{token}}

--MyBoundary
Content-Disposition: form-data; name="file"; filename="1.png"
Content-Type: application/octet-stream

< .\my-file.png
--MyBoundary
Content-Disposition: form-data; name="ProspectId"

1
--MyBoundary--

But a thing of note is that if the request boundaries are wrong the request never completes, it just sits there 'working' forever (or until you cancel it).

All 6 comments

@Timbuktu1982 nice catch, I have fixed this issue and will publish in next release.

@Timbuktu1982 you can try the latest version to verify

@Huachao : Many thanks for the quick help!

@Huachao I think this issue may have regressed.

v0.23.1 of REST Client
c1.41.1 VS Code.
Windows 10x64

Fails:

POST /v1/myendpoint HTTP/1.1
Host: localhost:12000
Accept: application/json
Content-Type: multipart/form-data; boundary=----MyBoundary
Authorization: Bearer {{token}}

----MyBoundary
Content-Disposition: form-data; name="file"; filename="1.png"
Content-Type: application/octet-stream

< .\my-file.png
----MyBoundary
Content-Disposition: form-data; name="ProspectId"

1
----MyBoundary--

my-file.png is in the same directory as the script file. Content-Length submitted to the server correctly reflects this (hence the file has been located and can be read), however the file is never transmitted/it hangs forever (with the "Waiting" in the bar.

Removing the file component of the form results in the request completing quickly (37ms).

I've tried with various file types, Content-Types and positions within the multipart form. None work.

@Ashthos I can't repro this. Could you please check your server side? Or try to downgrade to the old versions.

Hi @Huachao,

My humble apologies, it was an error in my request composition that was causing the problem. I'll document it here so that others hopefully do not fall into the same trap.

The RFC on multipart/form (https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html) states the BNF form of the boundary to be:

boundary := 0*69 bcharsnospace
delimiter := CRLF "--" boundary
close-delimiter := delimiter "--"

In my example above, I had the same boundary and delimiter values (i.e. delimiter should have an additional -- before it).

A working request: (Note the boundary= value in comparison with my non-working version)

POST /v1/myendpoint HTTP/1.1
Host: localhost:12000
Accept: application/json
Content-Type: multipart/form-data; boundary=MyBoundary
Authorization: Bearer {{token}}

--MyBoundary
Content-Disposition: form-data; name="file"; filename="1.png"
Content-Type: application/octet-stream

< .\my-file.png
--MyBoundary
Content-Disposition: form-data; name="ProspectId"

1
--MyBoundary--

But a thing of note is that if the request boundaries are wrong the request never completes, it just sits there 'working' forever (or until you cancel it).

Was this page helpful?
0 / 5 - 0 ratings