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

Post method with zip file #1017

Closed
rapw3k opened this issue Jul 22, 2016 · 13 comments
Closed

Post method with zip file #1017

rapw3k opened this issue Jul 22, 2016 · 13 comments

Comments

@rapw3k
Copy link

rapw3k commented Jul 22, 2016

Swagger File

swagger: '2.0'
info:
  version: 1.0.0
  title: Basic Example
  description: |
    An example 
host: sandbox.wf4ever-project.org
basePath: /rodl
consumes:
  - application/zip
  - multipart/form-data
produces:
  - text/plain
  - text/turtle
schemes:
  - http
  - https
securityDefinitions:
  Bearer:
    type: apiKey
    name: Authorization
    in: header
paths:
  /ROs:
    get:
      security:
        - Bearer: []
      responses:
        '200':
          description: >-
            Will send `Authenticated` if authentication is succesful, otherwise
            it will send `Unauthorised`
  /zip/create:
    post:
      security:
        - Bearer: []
      summary: Creates a new Reserch Object
      description: Creates a new Reserch Object
      responses:
        '201':
          description: Created
      parameters:
        - name: slug
          in: header
          description: Identifier of the research object.
          type: string
        - name: zipfile
          in: formData
          description: content in zip format
          type: file
  • Version: 2.0 (running on a linux ubuntu server)
  • Browser/OS: Chrome and Safari (with cross-origin resource sharing disabled), Mac OSX El Capitan

Issue

Hi,
I am trying to use the method "/zip/create" above, but I am unable to send correctly the request. After reading documentation, I understand in order to post a file you need to send it using "formData" and type "file", and use "multipart/form-data" in the consumes parameter. However, this returns: Status Code:415 Unsupported Media Type (see screenshot below). I cannot find the way to specify the "application/zip" as well in the call. How is this possible?

Thanks in advance.
Raul

You can test using the authentication: Bearer 4e5b6138-5885-4c8f-a794-cf368c67a4e4
screen shot 2016-07-22 at 17 21 34

@saharj
Copy link
Contributor

saharj commented Jul 25, 2016

Tryoperation has some bugs, specially with file uploads. Maybe we should refactor it.

@rapw3k
Copy link
Author

rapw3k commented Jul 26, 2016

Thanks, what do you mean by try operation? How to track any progress on this?

@saharj
Copy link
Contributor

saharj commented Jul 27, 2016

Try Operation is the component you see after you click on Try this operation.

@rapw3k
Copy link
Author

rapw3k commented Aug 4, 2016

Hi,
I think my issue here is exactly the problem described in swagger-api/swagger-core#636 and OAI/OpenAPI-Specification#222.

@webron mentioned that this feature request was added for the next proposal (Dec 2, 2014). Is there any news on this?

Alternatively @webron also mentioned that vendor extensions can be used to extend this functionality. Could you point to those vendor extensions?

@webron
Copy link
Contributor

webron commented Aug 4, 2016

There's no solution for it yet, and we haven't covered that in the talks about the next version of the spec. Vendor extensions are pretty much your extensions that you write, they will not add functionality magically, but they can be used by various tools to extend the functionality. If you want a tool to understand your extension, it's up to you to modify it to support it.

@rapw3k
Copy link
Author

rapw3k commented Aug 10, 2016

Alternatively, @webron is there any way to send the file in the body, like the equivalent in curl:

curl -X POST --verbose --data-binary "@aggregatedNoFolder.zip" -H "slug: mytest2" -H "Accept: application/json" -H "Content-Type: application/zip" -H "Authorization: Bearer 4e5b6138-5885-4c8f-a794-cf368c67a4e4" http://sandbox.wf4ever-project.org/rodl/zip/create

@webron
Copy link
Contributor

webron commented Aug 11, 2016

Sure, the tooling may not quite support it, but you can always say the method consumes application/zip and has a single empty schema as the body (since there's no real way to represent it).

@rapw3k
Copy link
Author

rapw3k commented Aug 12, 2016

Thanks for the answer, but I am not sure how would you do something like this in the swagger file. I can say that the file parameter is in body, but how to send it ? how would you define the parameter to pass the zip file to the service (e.g., zipfile parameter in the example below) @webron ?

parameters:
        - name: slug
          in: header
          description: Identifier of the research object.
          type: string
        - name: zipfile
          in: formData
          description: content in zip format
          type: file

something like this won't pass any file:

        -name: zipfile
          in: body
          description: content in zip format
          schema:
            type: string 

@webron
Copy link
Contributor

webron commented Aug 12, 2016

I don't really understand the question.

@rapw3k
Copy link
Author

rapw3k commented Aug 16, 2016

The question is how can you send a zip file in a POST method from the swagger file, to achieve the same behaviour as the curl command below:

curl -X POST --verbose --data-binary "@aggregatedNoFolder.zip" -H "slug: mytest2" -H "Accept: application/json" -H "Content-Type: application/zip" -H "Authorization: Bearer 4e5b6138-5885-4c8f-a794-cf368c67a4e4" http://sandbox.wf4ever-project.org/rodl/zip/create

At the moment I can send the file using parameter type "formData", but I cannot say that its a zip file, as the consumes has to be "multipart/form-data", so I receive Status Code:415 Unsupported Media Type. With a parameter type "body", as you proposed, I don't see how can I send a file.

@webron
Copy link
Contributor

webron commented Aug 16, 2016

Okay, let's separate things. Do what you want to do, you'd need to set it as a body parameter. The tools, specifically, the editor and the ui, do not support this form of file upload, and I doubt they will soon.

@saharj
Copy link
Contributor

saharj commented Sep 30, 2016

This PR may has fixed this issue.

@saharj
Copy link
Contributor

saharj commented Dec 29, 2016

This issue should be fixed with the latest PR #1141 . Please let us know if you still see the issue.

@saharj saharj closed this as completed Dec 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants