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

Feature/produces file #228

Open
wants to merge 6 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@ryo-nbx
Copy link

ryo-nbx commented May 30, 2018

This is only a merge resolve of the PR #154

So the original contributor of the code is vkagamlyk

Since the original PR has merge conflicts since almost a year I merged it to speed up the request.

@ryo-nbx

This comment has been minimized.

Copy link

ryo-nbx commented May 31, 2018

  • added support for static file download, use FileResult.path for static files and FileResult.data for generated file
  • you can offer a target file name with FileResult.filename but it will only be usable for static files
  • if no path and no file data is provided status code 404 will be returned
@ryo-nbx

This comment has been minimized.

Copy link

ryo-nbx commented Jun 1, 2018

last update for now...

  • found a problem with usage of instanceof FileResult and anonymous object generation
    • added some convinience functions to FileResult to improve Handling
@SuccessResponse('200', 'successful')
@Produces('application/zip, application/octet-stream')
@Get('download/backup')
public async downloadBackup (): Promise<FileResult> {
    const store = service.getBackupStorage()
    await service.exportSystemBackup(store.fullPath)

    // does NOT WORK with instanceof
    // return { path: store.fullPath }

    // does work
    // const result = new FileResult()
    // result.path = store.fullPath
    // return result

    // does work
    // return new FileResult({ path: store.fullPath })

    // does work
    return FileResult.newInstance({ path: store.fullPath })
  }
  • use sendFile() instead of Response.download() to achieve better compatibility with Swagger console
    • path must be absolute or specify root to res.sendFile
@jamestharpe

This comment has been minimized.

Copy link
Contributor

jamestharpe commented Jun 8, 2018

Is something needed to help get this pull request accepted? I'd really like to have this feature.

@qqnc

This comment has been minimized.

Copy link
Contributor

qqnc commented Aug 12, 2018

Need this feature. +1 Thanks

@fhewitt

This comment has been minimized.

Copy link

fhewitt commented Sep 12, 2018

In conflict again... :( This is a reasonable change, and a highly needed feature.

A part of me want to take the branch and resolve the conflicts, but it's a waste of time if the PR just stay there until new conflicts emerge. :(

Merge branch 'master' into feature/produces-file
# Conflicts:
#	src/routeGeneration/templates/express.ts
#	src/swagger/swagger.ts
#	tests/fixtures/express/routes.ts
#	tests/fixtures/inversify/routes.ts
@ryo-nbx

This comment has been minimized.

Copy link

ryo-nbx commented Sep 12, 2018

Fixed!

Merge branch 'master' into feature/produces-file
# Conflicts:
#	src/index.ts
#	src/metadataGeneration/tsoa.ts
@ryo-nbx

This comment has been minimized.

Copy link

ryo-nbx commented Sep 21, 2018

https://blog.nubix.de/index.php/2018/09/21/file-download-and-upload-with-tsoa-hack/

I put an example online demonstrating how to achieve upload and download files with the current version of TSOA. Downloading is a little bit dirty since file responses are not handled yet by TSOA.

I hope the example might help some user here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment