@jrmc/adonis-attachment
Version:
Turn any field on your Lucid model to an attachment data type
94 lines (67 loc) • 2.15 kB
Markdown
This package is currently development and will replace [attachment-advanced](https://github.com/batosai/attachment-advanced) for AdonisJS 6.
> Ready for AdonisJS 7 🎉
[](https://adonis-attachment.jrmc.dev/)
[](https://adonis-attachment.jrmc.dev/changelog.html)
Project sample : [adonis-starter-kit](https://github.com/batosai/adonis-starter-kit)
- [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 file by Base64
- [x] attachment files
- [x] save meta data
- [x] variantes
- [x] images
- [x] [blurhash](https://blurha.sh/)
- [x] documents thumbnail
- [x] videos thumbnail
- [x] command regenerate
- [x] command make:convert
- [x] adonis-drive/flydrive
- [x] jobs queue
- [x] serialize
- [x] attachments route
Install and configure the package:
```sh
node ace add @jrmc/adonis-attachment
```
If you use an AI coding agent (Claude Code, Cursor, Codex...), you can install skills that teach it the package API, variants/converters configuration and version migrations:
```sh
npx skills add batosai/adonis-attachment
```
## Sample
Simple upload file
```ts
// app/models/user.ts
import { BaseModel } from '@adonisjs/lucid/orm'
import { attachment } from '@jrmc/adonis-attachment'
import type { Attachment } from '@jrmc/adonis-attachment/types/attachment'
class User extends BaseModel {
@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="" />
```
Read [documentation](https://adonis-attachment.jrmc.dev/) for advanced usage(thumbnail video/pdf/doc, create from buffer/base64...)