Go-swagger: Files — returning proper content-type/filenames through runtime.File?

Created on 22 May 2017  Â·  2Comments  Â·  Source: go-swagger/go-swagger

Problem statement

What's the proper way to go about handling file downloads in the swagger yaml spec and in the handler code? Attempting to get proper content-types and filenames in the process

This works but returns the file but without any headers, despite explicitly setting 'em

paths:
  /geturl/
    get:
      produces:
        - application/octet-stream
      responses:
        '200':
          description: OK
          schema:
            type: file
f, _ := os.Open("somefile.zip")
h := make(textproto.MIMEHeader)
h.Set("Content-Type", "application-zip")
header := multipart.FileHeader{Filename: "returnfilename.zip", Header: h}
return operations.NewGetDataOK().WithPayload(runtime.File{Data: f, Header: &header})

Tried setting produces to the resulting file type (application/zip), but that did not work at all (no files got passed through)?

Environment

swagger version: 0.10.0
go version: 1.8.1
OS: Mac OS X

question

Most helpful comment

You could look at using type: string format: binary and use the content-disposition header to provide the filename

All 2 comments

You could look at using type: string format: binary and use the content-disposition header to provide the filename

thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings