Introduction
This Minio middleware is written for Node.js Express apps to use Minio to store files.
Files can be uploaded to a predefined folder in a predefined bucket in a Minio sever. Once a file has been uploaded successfully, you will be informed of the filename known to Minio for this file. Later on, you can use this filename to download or delete the file.
The Minio middleware also allows you to list all files stored inside the predefined folder in the predefined bucket in Minio.
How to use the package?
First of all, install the package:
npm i express-middleware-minio
Or
yarn add express-middleware-minio
Second, you need to add .env to get it up running, e.g.:
MINIO_ACCESS_KEY=xxxMINIO_SECRET_KEY=xxxMINIO_ENDPOINT='192.111.111.131'MINIO_PORT=9000MINIO_SECURITY=falseMINIO_BUCKET=manuscriptsMINIO_UPLOADS_FOLDER_NAME=uploads
Then you can use the Minio middleware in your Express application:
Four operations are provided:
- post
- get (deprecated)
- getStream
- delete
- list
You can use them the following way:
const expressMinio = console
You can find below an example.
const expressMinio = const minioMiddleware = expressMinio; // Upload a fileapp // List all filesapp // Download a fileapp // Delete a fileapp
Configuration
logger (optional)
By default, console is used for logging. You can override the logger with Node-config.
Here is an example config/default.js:
const logger = logger moduleexports = logger
Temporary directory (optional and deprecated)
Currently when retrieving a file from Minio via operation get (see above), we download and save it in the local filesystem, and then return it to the client.
This is the directory used to hold the file in the local filesystem. Be default, it is /tmp. You can change it to a different directory if necessary.
Here is an example config/default.js:
moduleexports = minioTmpDir: '/tmp'
Note: the recommended way is to use operation getStream, which would pipe the stream of the requested file to the client. If you use getStream way, you don't need to set up the temporary directory.