mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[GH-ISSUE #2293] [bug]: Cannot POST a file to a REST endpoint using multipart/form-data #791
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#791
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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?
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:
This issue:
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:
Environment
Production
Version
Cloud
@nvnputta commented on GitHub (Apr 27, 2022):
Hi, I am planning to work on fixing this issue and contribute back by creating a PR
@AndrewBastin commented on GitHub (Apr 27, 2022):
Sure thing @nvnputta.
Assigning!
@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.
@AndrewBastin commented on GitHub (May 31, 2022):
@nvnputta are you working on this ? please update your status.
@JacekAndrzejewski commented on GitHub (Jun 2, 2022):
Seems multipart is a bit buggy right now, this might be connected to #2390
@AndrewBastin commented on GitHub (Jun 13, 2022):
Unassigning @nvnputta due to inactivity.
@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
< 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:
@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. 😄
@AndrewBastin commented on GitHub (Aug 26, 2022):
@fumblehool sure! Assigning!
@AndrewBastin commented on GitHub (Oct 6, 2022):
@cloudomatic on further reference of your given command
This will actually add a form data entry named
datato 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.
@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.