Skip to content

batosai/adonis-attachment

Repository files navigation

AdonisJS attachment

This package is currently development and will replace attachment-advanced for AdonisJS 6.

Project sample : adonis-starter-kit

Links

View documentation

ChangeLog

Discord

⚠️ Breaking change version 2, include @adonisjs/drive

Roadmap

  • attachment file by file system
  • save meta data
  • variantes
    • images
    • documents thumbnail
    • videos thumbnail
  • command regenerate
  • command make:convert
  • adonis-drive/flydrive
  • jobs queue
  • serialize

Setup

Install and configure the package:

node ace add @jrmc/adonis-attachment

Sample

Simple upload file

// 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
}

// 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()
  }
}

<img src="{{ await user.avatar.getUrl() }}" loading="lazy" alt="" />

Read documentation for advanced usage(thumbnail video/pdf/doc, create from buffer/base64...)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published