adonis-4-cloudinary
v1.0.2
Published
Cloudinary Service Provider for Adonis 4.0
Downloads
13
Maintainers
Readme
Cloudinary Service Provider for Adonis 4.0
Installation
- Turn your ultra instinct mode on
$ npm install adonis-4-cloudinary --save
- Update your
.env
file with your Cloudinary Credentials
CLOUDINARY_NAME=supersaiyan777
CLOUDINARY_API_KEY=superbabidikey
CLOUDINARY_API_SECRET=ultrainstinctbabidi
- Create
config/cloudinary.js
file in your project
const Env = use('Env')
module.exports = {
name: Env.get('CLOUDINARY_NAME', ''),
api_key: Env.get('CLOUDINARY_API_KEY', ''),
api_secret: Env.get('CLOUDINARY_API_SECRET', '')
}
- Register the
adonis-4-cloudinary
in the service providers instart/app.js
const providers = [
...
'adonis-4-cloudinary/provider/Cloudinary'
]
const aliases = {
...
Cloudinary: 'Adonis/Addons/AdonisCloudinary'
}
Basic Usage
- In
app/Controllers/Http/UserController.js
'use strict'
const Cloudinary = use('Cloudinary')
class UserController {
async updateProfilePic({ request, response }) {
let profilePic = request.file('profile_pic', { types: ['image'], size: '2mb' })
let cloudinaryMeta = await Cloudinary.uploader.upload(profilePic.tmpPath)
request.user.profilePic = cloudinaryMeta.secure_url
await request.user.save()
return response.redirect('back')
}
}
module.exports = UserController