Start Here
Simple upload file
ts
// app/models/user.ts
import { BaseModel } from '@adonisjs/lucid/orm'
import { compose } from '@adonisjs/core/helpers'
import { attachment, Attachmentable } from '@jrmc/adonis-attachment'
import type { Attachment } from '@jrmc/adonis-attachment/types/attachment'
class User extends compose(BaseModel, Attachmentable) {
@attachment()
declare avatar: Attachment
}
ts
// app/controllers/users_controller.ts
import { attachmentManager } from '@jrmc/adonis-attachment'
class UsersController {
public store({ request }: HttpContext) {
const avatar = request.file('avatar')!
const user = new User()
user.avatar = await attachmentManager.createFromFile(avatar)
await user.save()
}
}
edge
<img src="{{ await user.avatar.getUrl() }}" loading="lazy" alt="" />