Skip to content

covenix / FileResponse

Class: FileResponse ​

Defined in: src/file-response.ts:41

A non-JSON response: a binary body (a Uint8Array/Buffer or a Readable stream) that covenix streams to the client, setting Content-Type and Content-Disposition and skipping JSON serialization and response validation. Return one from a handler (typically alongside @ReturnsFile).

Example ​

ts
@Get('{id}/export')
@ReturnsFile(200, { contentType: 'text/csv' })
export(@Param('id') id: string): FileResponse {
  return new FileResponse(Buffer.from(csv), {
    contentType: 'text/csv',
    filename: `user-${id}.csv`,
  });
}

Extends ​

Constructors ​

Constructor ​

new FileResponse(body, options?): FileResponse

Defined in: src/file-response.ts:51

Parameters ​

body ​

Uint8Array<ArrayBufferLike> | Readable

options? ​

FileResponseOptions = {}

Returns ​

FileResponse

Overrides ​

ResponseBase.constructor

Properties ​

body ​

readonly body: Uint8Array<ArrayBufferLike> | Readable

Defined in: src/file-response.ts:43

The response body — raw bytes or a readable stream.


contentType ​

readonly contentType: string | undefined

Defined in: src/file-response.ts:45

Content-Type for the response, if set.


cookies ​

readonly cookies: ResponseCookie[] | undefined

Defined in: src/response.ts:63

Cookies to set (each its own Set-Cookie), if any.

Inherited from ​

ResponseBase.cookies


disposition ​

readonly disposition: "inline" | "attachment" | undefined

Defined in: src/file-response.ts:49

Content-Disposition type ('inline'/'attachment'), if set.


filename ​

readonly filename: string | undefined

Defined in: src/file-response.ts:47

Download filename for Content-Disposition, if set.


headers ​

readonly headers: Record<string, HeaderValue> | undefined

Defined in: src/response.ts:61

Extra response headers, if set.

Inherited from ​

ResponseBase.headers


status ​

readonly status: number | undefined

Defined in: src/response.ts:59

Explicit HTTP status, if set.

Inherited from ​

ResponseBase.status

Methods ​

fromPath() ​

static fromPath(path, options?): FileResponse

Defined in: src/file-response.ts:60

Builds a FileResponse that streams the file at path from disk.

Parameters ​

path ​

string

options? ​

FileResponseOptions

Returns ​

FileResponse