Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@travetto/asset-rest

Package Overview
Dependencies
Maintainers
0
Versions
317
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/asset-rest

Provides integration between the travetto asset and rest module.

latest
Source
npmnpm
Version
4.1.6
Version published
Maintainers
0
Created
Source

Asset Rest Support

Provides integration between the travetto asset and rest module.

Install: @travetto/asset-rest

npm install @travetto/asset-rest

# or

yarn add @travetto/asset-rest

This module provides a clean and direct mechanism for processing uploads, built upon @fastify/busboy. The module also provides some best practices with respect to temporary file deletion.

Once the files are uploaded, they are exposed on RESTful API's request object as req.files. The uploaded files are constructed as Asset instances, which allows for integration with the Asset module.

A simple example:

Code: Rest controller with upload support

import { Controller, Post, Get, Request } from '@travetto/rest';
import { Asset } from '@travetto/asset';
import { AssetRestUtil, Upload, UploadAll } from '@travetto/asset-rest';

@Controller('/simple')
export class Simple {

  @Get('/age')
  getAge() {
    return { age: 50 };
  }

  @Post('/age')
  getPage() {
    return { age: 20 };
  }

  /**
   * @param file A file to upload
   */
  @Post('/file')
  loadFile(@Upload() file: Asset) {
    return AssetRestUtil.downloadable(file);
  }

  /**
   * @param file A file to upload
   */
  @Post('/files')
  @UploadAll()
  loadFiles({ files }: Request) {
    for (const [, file] of Object.entries(files)) {
      return AssetRestUtil.downloadable(file); // return the first
    }
  }
}

Keywords

rest

FAQs

Package last updated on 02 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts