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

Support for file uploads? #6

Open
jessefulton opened this issue Nov 20, 2013 · 3 comments
Open

Support for file uploads? #6

jessefulton opened this issue Nov 20, 2013 · 3 comments

Comments

@jessefulton
Copy link
Contributor

First off, this and restify-swagger are awesome - thanks!

I'm trying to add a file upload to a post request, but can't seem to figure it out. Is this supported?

server.post
    url: "/upload"
    swagger:
        summary: "Upload"
        notes: "upload a video"
        nickname: "upload"
    validation:
        videoFile:
            dataType: "file"
            isRequired: true
            scope: "body"
            description: "Video File"
        title:
            isString: true
            isRequired: true
            scope: "body"
            description: "Video Title"
@z0mt3c
Copy link
Owner

z0mt3c commented Nov 21, 2013

Actually i never really managed to get the swagger file-upload stuff working. But i have to admit - i didn't try much ;-)

Feel free to try and contribute if you are successful! I just updated the module with some changes which might bring you a bit closer (swagger-ui has been updated as well in the demo project).

You can start here ;-)

server.post({url: '/upload',
    swagger: {
        summary: 'x',
        notes: 'y',
        nickname: 'z'
    },
    validation: {
        uploadFile: {
            swaggerType: "file",
            isRequired: false,
            scope: "body",
            description: "Video File"
        }
    }}, function (req, res, next) {
    res.send(req.params);
});

@jessefulton
Copy link
Contributor Author

Yea, I'm stuck around here...

server.post
    url: "/upload"
    swagger:
        summary: "Upload a video and thumbnail"
        notes: ""
        nickname: ""
        consumes: [ # which of these do we need?
            "multipart/form-data"
            "application/json"
            "image/jpeg"
            "video/x-m4v"
            "application/x-www-form-urlencoded"
        ]
    validation:
        video:
            swaggerType: "file"
            parameterType: "form"
            scope: "body"
            isRequired: false
            description: "Video"
        thumbnail:
            swaggerType: "file"
            parameterType: "form"
            scope: "body"
            isRequired: false
            description: "Video Thumbnail"
        title:
            isString: true
            isRequired: true
            scope: "body"
            description: "Video Title"

If I select multipart/form for the fields in the swagger ui, then I get "bad content-type header, no multipart boundary." If I try to set each field to it's correct type, not all of them come through... Not sure if this is an issue with Swagger or restify-validation.

Thoughts?

@z0mt3c
Copy link
Owner

z0mt3c commented Nov 22, 2013

Hmm, i see the issue... you can simply unload restify-validation. restify-swagger doesnt depend on the usage of the validation module. But it doesnt change anything. From my point of view the requests which is generated by swagger/swagger-ui itself looks strange.

Hm, anything wrong in here?

{
    "notes": null,
    "nickname": "Upload",
    "produces": ["application/json"],
    "consumes": ["multipart/form-data", "application/json", "image/jpeg", "video/x-m4v", "application/x-www-form-urlencoded"],
    "responseMessages": [{
        "code": 500,
        "message": "Internal Server Error"
    }],
    "parameters": [{
        "type": "file",
        "dataType": "file",
        "name": "video",
        "description": "Video",
        "paramType": "body"
    }, {
        "type": "file",
        "dataType": "file",
        "name": "thumbnail",
        "description": "Video Thumbnail",
        "paramType": "body"
    }, {
        "name": "Body",
        "description": "Upload a video and thumbnail",
        "required": true,
        "dataType": "Upload",
        "paramType": "body"
    }],
    "summary": "Upload a video and thumbnail",
    "httpMethod": "POST",
    "method": "POST"
}

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

No branches or pull requests

2 participants