@jrmc/adonis-attachment
TypeScript icon, indicating that this package has built-in type declarations

4.0.4 • Public • Published

AdonisJS attachment

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

Links

View documentation

ChangeLog

Discord

Project sample : adonis-starter-kit

Roadmap

  • [x] attachment file by file system
  • [x] attachment file by buffer
  • [x] attachment file by path
  • [x] attachment file by url
  • [x] attachment file by stream
  • [x] attachment files
  • [x] save meta data
  • [x] variantes
    • [x] images
    • [x] documents thumbnail
    • [x] videos thumbnail
  • [x] command regenerate
  • [x] command make:convert
  • [x] adonis-drive/flydrive
  • [x] jobs queue
  • [x] 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...)

Package Sidebar

Install

npm i @jrmc/adonis-attachment

Weekly Downloads

256

Version

4.0.4

License

MIT

Unpacked Size

235 kB

Total Files

120

Last publish

Collaborators

  • batosai