Skip to content
New issue

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

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

Already on GitHub? # to your account

POST formData not working on http://editor.swagger.io/ #3629

Closed
dannoehe opened this issue Aug 31, 2017 · 4 comments
Closed

POST formData not working on http://editor.swagger.io/ #3629

dannoehe opened this issue Aug 31, 2017 · 4 comments

Comments

@dannoehe
Copy link

dannoehe commented Aug 31, 2017

I am trying http://editor.swagger.io/ to edit API doc, "formData" can be used to indicate the input parameter as form data and I assume such parameter can be parsed on server side to get its name and value, but actually server hangs and timeouts.

Example:

  • client side:
'/Buckets/{bucket}/upload':
    post:
      parameters:
        - in: path
          name: bucket
          description: Name of bucket where the file is uploaded
          required: true
          type: string
        - in: formData
          name: name
          description: file name to upload
          required: false
          type: string
  • on right side of UI on http://editor.swagger.io/, I can see the request is translated to curl command like below,
    curl -X POST "http://127.0.0.1:3002/api/v1/Buckets/bucket-test/upload" -H "accept: application/json" -H "content-type: application/x-www-form-urlencoded" -d "name=testFileName"
  • I think the right curl command for it should change "-d" as "-F", like this which I verified correct.
    curl -X POST "http://127.0.0.1:3002/api/v1/Buckets/bucket-test/upload" -H "accept: application/json" -H "content-type: application/x-www-form-urlencoded" -F "name=testFileName"
  • on server side, it hangs to parse request body, timeouts and returns error "Error: Request aborted"

This issue seems like #838 which was resolved in 2015, but is the fix missed on this online tool? If not same one, could you please help on this? Thanks!

@webron
Copy link
Contributor

webron commented Aug 31, 2017

What do you have the consumes set for the operation?

@dannoehe
Copy link
Author

dannoehe commented Sep 1, 2017

@webron, it is set as below.

consumes:
        - application/x-www-form-urlencoded

@webron
Copy link
Contributor

webron commented Sep 5, 2017

From curl's man page:

        -d, --data <data>
              (HTTP)  Sends  the specified data in a POST request to the HTTP server, in the same way that a
              browser does when a user has filled in an HTML form and presses the submit button.  This  will
              cause curl to pass the data to the server using the content-type application/x-www-form-urlen-
              coded.  Compare to -F, --form.
       -F, --form <name=content>
              (HTTP)  This lets curl emulate a filled-in form in which a user has pressed the submit button.
              This causes curl to POST data using the  Content-Type  multipart/form-data  according  to  RFC
              2388.  This  enables  uploading of binary files etc. To force the 'content' part to be a file,
              prefix the file name with an @ sign. To just get the content part from a file, prefix the file
              name  with  the  symbol  <.  The  difference  between  @ and < is then that @ makes a file get
              attached in the post as a file upload, while the < makes a text field and just  get  the  con-
              tents for that text field from a file.

Based on the media type you provided, it seems the curl command is correct.

@shockey
Copy link
Contributor

shockey commented Sep 12, 2017

Closing due to (a) inactivity, (b) apparent decision for non-action on this. Thanks for the report!

@shockey shockey closed this as completed Sep 12, 2017
@lock lock bot locked and limited conversation to collaborators Jul 2, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

3 participants