plezanje-net / api

NestJS GraphQL web server
GNU General Public License v3.0
7 stars 2 forks source link

Upload for images #138

Closed salamca closed 2 years ago

salamca commented 2 years ago

Adds fastify-multipart library which enables multipart forms handling needed for uploading files.

Adds a new controller (not GQL resolver) with an image method that handles the image upload.

Type of file that can be processed is limited by Sharp library which will throw an exception if the passed in file is not an image.

Size of file is not limited, but original gets downsized and discarded anyway. Right now 6kx6k images (or smaller) are kept, and sizes 300w, 600w and 1040w are generated for FE use. Should discuss further on wether additional sizes are needed.

note: LoaderInterceptor is globally disabled, since we should not intercept non GQL requests Instead all resolvers that use Loaders should be (are) decorated individually.

To test: Using Postman post form-data to upload/image endpoint with the following fields: entityType: string entityId: string title: string (optional) description: string (optional) type: string (optional) image: file

(+auth token)

!The order of fields is important. image file should be last!

closes BE part of: https://github.com/plezanje-net/web/issues/229