Page Contents

Home > @loopback/openapi-v3 > response > file

response.file() function

Decorate the response as a file

Signature:

file: (...mediaTypes: string[]) => MethodDecorator

Parameters

Parameter Type Description
mediaTypes string[] A list of media types for the file response. It’s default to ['application/octet-stream'].

Returns:

MethodDecorator

Example

import {oas, get, param} from '@loopback/openapi-v3';
import {RestBindings, Response} from '@loopback/rest';

class MyController {
  @get('/files/{filename}')
  @oas.response.file('image/jpeg', 'image/png')
  download(
    @param.path.string('filename') fileName: string,
    @inject(RestBindings.Http.RESPONSE) response: Response,
  ) {
    // use response.download(...);
  }
}