[GH-ISSUE #2293] [bug]: Cannot POST a file to a REST endpoint using multipart/form-data #791

Closed
opened 2026-03-16 17:12:25 +03:00 by kerem · 11 comments
Owner

Originally created by @cloudomatic on GitHub (Apr 25, 2022).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2293

Originally assigned to: @fumblehool, @AndrewBastin on GitHub.

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I operate a REST endpoint that takes a file as input, and would like to test it using a afile. If I curl this command, I will get my file back from httpbin.org in the response body:

       curl -vks -X POST -F data=@petstore_swagger.json  https://httpbin.org/post

This issue:

https://github.com/hoppscotch/hoppscotch/issues/1679

suggests that this is supported in Hoppscotch, however I get a different result.

The HTTP response shows an empty file:

"files": { }

And says my content-type was: "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryKQngLTS8PbjO5yW7",

My expectation was that I would see the same "files" attribute that I see in the response body from my curl command, i.e. that my file body would be echoed back to me. (see steps to reproduce below)

Steps to reproduce

I create the equivalent of this request in the form at https://hoppscotch.io/ on a new REST request:

           1) Select POST
           2) Set the URL to https://httpbin.org/post
           3) Set content-type to multipart/form-data
           4) Click "Choose Files" and specify my file
           5) Click "send"

Environment

Production

Version

Cloud

Originally created by @cloudomatic on GitHub (Apr 25, 2022). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2293 Originally assigned to: @fumblehool, @AndrewBastin on GitHub. ### Is there an existing issue for this? - [X] I have searched the existing issues ### Current behavior I operate a REST endpoint that takes a file as input, and would like to test it using a afile. If I curl this command, I will get my file back from httpbin.org in the response body: curl -vks -X POST -F data=@petstore_swagger.json https://httpbin.org/post This issue: https://github.com/hoppscotch/hoppscotch/issues/1679 suggests that this is supported in Hoppscotch, however I get a different result. The HTTP response shows an empty file: "files": { } And says my content-type was: `"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryKQngLTS8PbjO5yW7",` My expectation was that I would see the same "files" attribute that I see in the response body from my curl command, i.e. that my file body would be echoed back to me. (see steps to reproduce below) ### Steps to reproduce I create the equivalent of this request in the form at https://hoppscotch.io/ on a new REST request: 1) Select POST 2) Set the URL to https://httpbin.org/post 3) Set content-type to multipart/form-data 4) Click "Choose Files" and specify my file 5) Click "send" ### Environment Production ### Version Cloud
kerem 2026-03-16 17:12:25 +03:00
Author
Owner

@nvnputta commented on GitHub (Apr 27, 2022):

Hi, I am planning to work on fixing this issue and contribute back by creating a PR

<!-- gh-comment-id:1110631312 --> @nvnputta commented on GitHub (Apr 27, 2022): Hi, I am planning to work on fixing this issue and contribute back by creating a PR
Author
Owner

@AndrewBastin commented on GitHub (Apr 27, 2022):

Sure thing @nvnputta.
Assigning!

<!-- gh-comment-id:1110900813 --> @AndrewBastin commented on GitHub (Apr 27, 2022): Sure thing @nvnputta. Assigning!
Author
Owner

@AndrewBastin commented on GitHub (Apr 27, 2022):

@cloudomatic Are you using the browser extension or Proxy or any other interceptor ?
I can't reproduce the issue when I tried.

<!-- gh-comment-id:1110965233 --> @AndrewBastin commented on GitHub (Apr 27, 2022): @cloudomatic Are you using the browser extension or Proxy or any other interceptor ? I can't reproduce the issue when I tried.
Author
Owner

@AndrewBastin commented on GitHub (May 31, 2022):

@nvnputta are you working on this ? please update your status.

<!-- gh-comment-id:1141985664 --> @AndrewBastin commented on GitHub (May 31, 2022): @nvnputta are you working on this ? please update your status.
Author
Owner

@JacekAndrzejewski commented on GitHub (Jun 2, 2022):

Seems multipart is a bit buggy right now, this might be connected to #2390

<!-- gh-comment-id:1144354089 --> @JacekAndrzejewski commented on GitHub (Jun 2, 2022): Seems multipart is a bit buggy right now, this might be connected to #2390
Author
Owner

@AndrewBastin commented on GitHub (Jun 13, 2022):

Unassigning @nvnputta due to inactivity.

<!-- gh-comment-id:1154199060 --> @AndrewBastin commented on GitHub (Jun 13, 2022): Unassigning @nvnputta due to inactivity.
Author
Owner

@cloudomatic commented on GitHub (Jul 14, 2022):

@AndrewBastin - This is without the proxy or extension(s), just running on Hoppscotch.io (deployed version on 2022/07/14). If you repeat the steps to reproduce, you'll see the "files" element of the JSON response body is an empty JSON object:

"files": {

},

If you do the same command with curl, the server (httpbin.org) acknowledges that you sent a file and echoes it back

$ echo "Hello world" > afile.txt
$ curl -vks -X POST -F data=@afile.txt https://httpbin.org/post

POST /post HTTP/2
Host: httpbin.org
user-agent: curl/7.68.0
accept: /
content-length: 199
content-type: multipart/form-data; boundary=------------------------2795e44954c00c38

  • Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
  • We are completely uploaded and fine
    < HTTP/2 200
    < date: Thu, 14 Jul 2022 13:27:32 GMT
    < content-type: application/json
    < content-length: 476
    < server: gunicorn/19.9.0
    < access-control-allow-origin: *
    < access-control-allow-credentials: true
    <

and you see the file echoed in the JSON response body:

{
"args": {},
"data": "",
"files": {
"data": "Hello world\n"
},
.... skipping .....
}

In the debugger, when using Hoppscotch.io, it looks like it doesn't actually send a file

{
"v": "1",
"endpoint": "https://httpbin.org/post",
"name": "Untitled request",
"params": [],
"headers": [],
"method": "POST",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
},
"preRequestScript": "",
"testScript": "",
"body": {
"contentType": "multipart/form-data",
"body": []
}
}

Even though I've selected a file and specified the content-type:

image

<!-- gh-comment-id:1184459499 --> @cloudomatic commented on GitHub (Jul 14, 2022): @AndrewBastin - This is without the proxy or extension(s), just running on Hoppscotch.io (deployed version on 2022/07/14). If you repeat the steps to reproduce, you'll see the "files" element of the JSON response body is an empty JSON object: "files": { }, If you do the same command with curl, the server (httpbin.org) acknowledges that you sent a file and echoes it back $ echo "Hello world" > afile.txt $ curl -vks -X POST -F data=@afile.txt https://httpbin.org/post > POST /post HTTP/2 > Host: httpbin.org > user-agent: curl/7.68.0 > accept: */* > content-length: 199 > content-type: multipart/form-data; boundary=------------------------2795e44954c00c38 > * Connection state changed (MAX_CONCURRENT_STREAMS == 128)! * We are completely uploaded and fine < HTTP/2 200 < date: Thu, 14 Jul 2022 13:27:32 GMT < content-type: application/json < content-length: 476 < server: gunicorn/19.9.0 < access-control-allow-origin: * < access-control-allow-credentials: true < and you see the file echoed in the JSON response body: { "args": {}, "data": "", "files": { "data": "Hello world\n" }, .... skipping ..... } In the debugger, when using Hoppscotch.io, it looks like it doesn't actually send a file { "v": "1", "endpoint": "https://httpbin.org/post", "name": "Untitled request", "params": [], "headers": [], "method": "POST", "auth": { "authType": "none", "authActive": true, "addTo": "Headers", "key": "", "value": "" }, "preRequestScript": "", "testScript": "", "body": { "contentType": "multipart/form-data", "body": [] } } Even though I've selected a file and specified the content-type: ![image](https://user-images.githubusercontent.com/22052216/178995039-de8f94d7-109c-4115-b61f-4eefe89bb210.png)
Author
Owner

@fumblehool commented on GitHub (Aug 26, 2022):

@AndrewBastin Hi, I would love to work on this bug.
If nobody is currently working on this, please assign this to me. 😄

<!-- gh-comment-id:1228881807 --> @fumblehool commented on GitHub (Aug 26, 2022): @AndrewBastin Hi, I would love to work on this bug. If nobody is currently working on this, please assign this to me. 😄
Author
Owner

@AndrewBastin commented on GitHub (Aug 26, 2022):

@fumblehool sure! Assigning!

<!-- gh-comment-id:1228932597 --> @AndrewBastin commented on GitHub (Aug 26, 2022): @fumblehool sure! Assigning!
Author
Owner

@AndrewBastin commented on GitHub (Oct 6, 2022):

@cloudomatic on further reference of your given command

curl -vks -X POST -F data=@petstore_swagger.json  https://httpbin.org/post

This will actually add a form data entry named data to your request.

In the request you have assembled in Hoppscotch, from the screenshot, I see you haven't assigned a key for the entry. Hoppscotch will filter out empty keys as 'invalid' which explains why it doesn't send the file.

Hence, I don't categorize #2664 as a fix for this PR, but since the spec doesn't have a proper definition about empty keys and looking at the precendence set by Insomnia, I will be allowing the PR.

<!-- gh-comment-id:1270642509 --> @AndrewBastin commented on GitHub (Oct 6, 2022): @cloudomatic on further reference of your given command ``` curl -vks -X POST -F data=@petstore_swagger.json https://httpbin.org/post ``` This will actually add a form data entry named `data` to your request. In the request you have assembled in Hoppscotch, from the screenshot, I see you haven't assigned a key for the entry. Hoppscotch will filter out empty keys as 'invalid' which explains why it doesn't send the file. Hence, I don't categorize #2664 as a fix for this PR, but since the spec doesn't have a proper definition about empty keys and looking at the precendence set by Insomnia, I will be allowing the PR.
Author
Owner

@liyasthomas commented on GitHub (Dec 8, 2023):

It seems this feature is available in Hoppscotch, hence I'm closing this issue ticket.
Do re-open or create another ticket if multipart/form-data has any errors.

<!-- gh-comment-id:1847513838 --> @liyasthomas commented on GitHub (Dec 8, 2023): It seems this feature is available in Hoppscotch, hence I'm closing this issue ticket. Do re-open or create another ticket if multipart/form-data has any errors.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#791
No description provided.