Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to send requests "multipart/form-data" that contains files #332

Closed
Timbuktu1982 opened this issue Feb 21, 2019 · 6 comments
Closed
Labels

Comments

@Timbuktu1982
Copy link

  • 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--

@Huachao Huachao added the bug label Feb 22, 2019
@Huachao
Copy link
Owner

Huachao commented Feb 22, 2019

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

@Huachao
Copy link
Owner

Huachao commented Mar 6, 2019

@Timbuktu1982 you can try the latest version to verify

@Timbuktu1982
Copy link
Author

@Huachao : Many thanks for the quick help!

@Ashthos
Copy link

Ashthos commented Jan 27, 2020

@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.

@Huachao
Copy link
Owner

Huachao commented Jan 28, 2020

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

@Ashthos
Copy link

Ashthos commented Jan 28, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants