Minio driver for AdonisJS Drive
- Minio
- AdonisJS Drive (
adonis install @adonisjs/drive
)
adonis install adonis-drive-minio
Make sure to register the provider inside start/app.js
file.
const providers = [
...
'adonis-drive-minio/providers/DriveProvider'
]
Add new configuration inside disks
module in config/drive.js
:
minio: {
driver: 'minio',
host: Env.get('MINIO_HOST'),
port: Env.get('MINIO_PORT'),
secure: Env.get('MINIO_SECURE'),
accessKey: Env.get('MINIO_ACCESS'),
secretKey: Env.get('MINIO_SECRET'),
bucket: Env.get('MINIO_BUCKET'),
region: Env.get('MINIO_REGION')
}
Add minio variables in .env
file:
MINIO_HOST=
MINIO_PORT=
MINIO_SECURE=
MINIO_ACCESS=
MINIO_SECRET=
MINIO_BUCKET=
MINIO_REGION=
Find if a file exists or not.
const isExists = await Drive.disk('minio').exists('adonis.jpeg')
Downloads and saves the object as a file in the local filesystem.
const path = await Drive.disk('minio').get('adonis.jpeg', Helpers.tmpPath('adonis.jpeg'))
Returns url for a given key. Note this method doesn't validates the existence of file or it's visibility status.
const url = await Drive.disk('minio').getUrl('adonis.jpeg')
Presigned URLs are generated for temporary download/upload access to private objects.
// url is valid for 10 minutes
const url = await Drive.disk('minio').getSignedUrl
('adonis.jpeg')
// url is valid for one hour
const url = await Drive.disk('minio').getSignedUrl
('adonis.jpeg', 3600)
Create a new file.
// url = bucketname/adonis.jpeg
const url = await Drive.disk('minio').put('/home/pictures/adonis.jpeg')
// url = bucketname/uploaded.jpeg
const url = await Drive.disk('minio').put('/home/pictures/adonis.jpeg', 'uploaded.jpeg')
Remove a file.
const isDeleted = await Drive.disk('minio').delete('adonis.jpeg')
Copy file from one location to another within.
// copied in the same bucket
const url = await Drive.disk('minio').copy('adonis.jpeg', 'adonis-2.jpeg')
// copied to "other-bucket" bucket
const url = await Drive.disk('minio').copy('adonis.jpeg', 'adonis-2.jpeg', 'other-bucket')
Move file from one location to another within.
// moved in the same bucket
const url = await Drive.disk('minio').move('adonis.jpeg', 'new-adonis.jpeg')
// moved to "other-bucket" bucket
const url = await Drive.disk('minio').move('adonis.jpeg', 'adonis-2.jpeg', 'other-bucket')
You can change bucket at runtime, just passing the bucket name before action.
const isExists = await Drive.disk('minio').bucket('new-bucket').exists('adonis.jpeg')
Special thanks to the creator(s) of AdonisJS for creating such a great framework.