### Install LibreOffice File Converter (yarn) Source: https://adonis-attachment.jrmc.dev/v4/guide/converters/document-thumbnail.html Install the necessary package using yarn. ```sh yarn add libreoffice-file-converter ``` -------------------------------- ### Install Fluent-FFmpeg for Video Thumbnails (yarn) Source: https://adonis-attachment.jrmc.dev/v4/guide/essentials/installation.html Install the fluent-ffmpeg module using yarn for generating video thumbnails. Ensure ffmpeg is installed on your system. ```sh yarn add fluent-ffmpeg ``` -------------------------------- ### Usage Examples: URL Management Source: https://adonis-attachment.jrmc.dev/v4/guide/basic_usage/attachment-object.html Examples demonstrating how to use the URL management methods to get file URLs and signed URLs. ```typescript // Getting the URL const url = await attachment.getUrl(); // Getting a variant URL const variantUrl = await attachment.getUrl('thumbnail'); // Getting a signed URL const signedUrl = await attachment.getSignedUrl({ expiresIn: '30m' }); // Getting a signed URL for a variant const signedVariantUrl = await attachment.getSignedUrl('thumbnail', { expiresIn: '30m' }); ``` -------------------------------- ### Install LibreOffice File Converter (npm) Source: https://adonis-attachment.jrmc.dev/v4/guide/converters/document-thumbnail.html Install the necessary package using npm. ```sh npm install libreoffice-file-converter ``` -------------------------------- ### Install LibreOffice File Converter (pnpm) Source: https://adonis-attachment.jrmc.dev/v4/guide/converters/document-thumbnail.html Install the necessary package using pnpm. ```sh pnpm install libreoffice-file-converter ``` -------------------------------- ### Install Fluent-FFmpeg for Video Thumbnails (npm) Source: https://adonis-attachment.jrmc.dev/v4/guide/essentials/installation.html Install the fluent-ffmpeg module using npm for generating video thumbnails. Ensure ffmpeg is installed on your system. ```sh npm install fluent-ffmpeg ``` -------------------------------- ### Install FFmpeg on Ubuntu Source: https://adonis-attachment.jrmc.dev/guide/converters/video-thumbnail.html Install FFmpeg on Ubuntu using apt-get. This is a prerequisite for video thumbnail generation. ```sh sudo apt-get install ffmpeg ``` -------------------------------- ### Install Fluent-FFmpeg for Video Thumbnails (pnpm) Source: https://adonis-attachment.jrmc.dev/v4/guide/essentials/installation.html Install the fluent-ffmpeg module using pnpm for generating video thumbnails. Ensure ffmpeg is installed on your system. ```sh pnpm install fluent-ffmpeg ``` -------------------------------- ### Install fluent-ffmpeg Source: https://adonis-attachment.jrmc.dev/v4/guide/converters/video-thumbnail.html Install the fluent-ffmpeg library using npm, pnpm, or yarn. This is a prerequisite for the video thumbnail converter. ```sh npm install fluent-ffmpeg ``` ```sh pnpm install fluent-ffmpeg ``` ```sh yarn add fluent-ffmpeg ``` -------------------------------- ### Install Node-Poppler for PDF Thumbnails (npm) Source: https://adonis-attachment.jrmc.dev/v4/guide/essentials/installation.html Install the node-poppler module using npm for generating PDF thumbnails. Ensure poppler is installed on your system. ```sh npm install node-poppler ``` -------------------------------- ### Install Node-Poppler for PDF Thumbnails (yarn) Source: https://adonis-attachment.jrmc.dev/v4/guide/essentials/installation.html Install the node-poppler module using yarn for generating PDF thumbnails. Ensure poppler is installed on your system. ```sh yarn add node-poppler ``` -------------------------------- ### Install Sharp for Image Variants with npm Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Install the sharp module using npm to enable image variant generation. ```sh npm install sharp ``` -------------------------------- ### Usage Examples: File Management Source: https://adonis-attachment.jrmc.dev/v4/guide/basic_usage/attachment-object.html Examples demonstrating how to use the file management methods to access file content. ```typescript // Getting the storage disk const disk = attachment.getDisk(); // Getting file content as bytes const bytes = await attachment.getBytes(); // Getting file content as buffer const buffer = await attachment.getBuffer(); // Getting file content as stream const stream = await attachment.getStream(); stream.pipe(fs.createWriteStream('output.jpg')); ``` -------------------------------- ### Install Poppler for PDF Thumbnails on Linux Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Install poppler-utils and poppler-data on Linux systems for PDF thumbnail generation. ```sh sudo apt-get install poppler-data poppler-utils ``` -------------------------------- ### Install Node-Poppler for PDF Thumbnails (pnpm) Source: https://adonis-attachment.jrmc.dev/v4/guide/essentials/installation.html Install the node-poppler module using pnpm for generating PDF thumbnails. Ensure poppler is installed on your system. ```sh pnpm install node-poppler ``` -------------------------------- ### Basic Route Setup Source: https://adonis-attachment.jrmc.dev/guide/basic_usage/route-setup.html Sets up the default route for accessing attachments. If a requested variant does not exist, it will be generated on the fly. ```typescript // start/routes.ts import router from '@adonisjs/core/services/router' router.attachments() ``` -------------------------------- ### Install Sharp Module Source: https://adonis-attachment.jrmc.dev/guide/converters/image.html Install the sharp module using npm, pnpm, or yarn. This module is required for image processing. ```bash npm install sharp ``` ```bash pnpm install sharp ``` ```bash yarn add sharp ``` -------------------------------- ### Install FFmpeg on macOS Source: https://adonis-attachment.jrmc.dev/guide/converters/video-thumbnail.html Install FFmpeg on macOS using Homebrew. This is a prerequisite for video thumbnail generation. ```sh brew install ffmpeg ``` -------------------------------- ### Install node-poppler Source: https://adonis-attachment.jrmc.dev/v4/guide/converters/pdf-thumbnail.html Install the node-poppler package using npm, pnpm, or yarn. This is a prerequisite for the PDF thumbnail converter. ```sh npm install node-poppler ``` ```sh pnpm install node-poppler ``` ```sh yarn add node-poppler ``` -------------------------------- ### Install Sharp for Image Variants with pnpm Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Install the sharp module using pnpm to enable image variant generation. ```sh pnpm install sharp ``` -------------------------------- ### Install Sharp for Image Variants with yarn Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Install the sharp module using yarn to enable image variant generation. ```sh yarn add sharp ``` -------------------------------- ### Install Poppler for PDF Thumbnails on macOS Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Install poppler on macOS using Homebrew for PDF thumbnail generation. ```sh brew install poppler ``` -------------------------------- ### Install Adonis Attachment Automatically Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Use this command to automatically install and configure the Adonis Attachment package. ```sh node ace add @jrmc/adonis-attachment ``` -------------------------------- ### Install Adonis Attachment Manually with pnpm Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Manually install the package using pnpm and then run the configure command. ```sh pnpm install @jrmc/adonis-attachment node ace configure @jrmc/adonis-attachment ``` -------------------------------- ### Install Adonis Attachment Manually with npm Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Manually install the package using npm and then run the configure command. ```sh npm install @jrmc/adonis-attachment node ace configure @jrmc/adonis-attachment ``` -------------------------------- ### Install Adonis Attachment Manually with yarn Source: https://adonis-attachment.jrmc.dev/guide/essentials/installation.html Manually install the package using yarn and then run the configure command. ```sh yarn add @jrmc/adonis-attachment node ace configure @jrmc/adonis-attachment ``` -------------------------------- ### Install Ace Command (v2.4.0) Source: https://adonis-attachment.jrmc.dev/changelog.html Command to install the Adonis Attachment package using the Ace CLI. ```shell node ace configure @jrmc/adonis-attachment ``` -------------------------------- ### Basic Model Setup with @attachment Source: https://adonis-attachment.jrmc.dev/guide/basic_usage/model-setup.html Import the attachment decorator and Attachment type. Do not use @column with @attachment. ```typescript 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 } ``` -------------------------------- ### Install @adonisjs/drive (v2.0.1) Source: https://adonis-attachment.jrmc.dev/changelog.html Command to install the required @adonisjs/drive package for Adonis Attachment version 2.0.1 and later. ```shell node ace add @adonisjs/drive ``` -------------------------------- ### Previous Thumbnail Configuration (v4) Source: https://adonis-attachment.jrmc.dev/migration.html This is an example of the thumbnail configuration in v4, where the 'options' attribute was not yet optional and was required for specifying converter options. ```typescript thumbnail: { converter: () => import('@jrmc/adonis-attachment/converters/autodetect_converter'), resize: 300, format: 'webp', } ``` -------------------------------- ### Configure Thumbnail Converter with Resize Object Source: https://adonis-attachment.jrmc.dev/guide/converters/image.html Configure a 'thumbnail' image converter using a resize object to specify width, height, fit, and position. This example uses sharp's cover fit and top position. ```typescript import { defineConfig } from '@jrmc/adonis-attachment' import { InferConverters } from '@jrmc/adonis-attachment/types/config' import sharp from 'sharp' const attachmentConfig = defineConfig({ converters: { thumbnail: { converter: () => import('@jrmc/adonis-attachment/converters/image_converter'), format: 'jpeg', resize: { // https://sharp.pixelplumbing.com/api-resize width: 400, height: 400, fit: sharp.fit.cover, position: 'top' }, } } }) export default attachmentConfig declare module '@jrmc/adonis-attachment' { interface AttachmentVariants extends InferConverters {} } ``` -------------------------------- ### Rendering Picture Component in Edge Source: https://adonis-attachment.jrmc.dev/guide/use-cases/picture-v2.html Example of how to render the Picture component within an Edge template, passing the article image and alt text as props. ```edge @!picture({ source: article.image, alt: "Image alt" }) ``` -------------------------------- ### Handle E_CANNOT_WRITE_FILE Exception with Session Flash and Redirect Source: https://adonis-attachment.jrmc.dev/guide/advanced_usage/exceptions.html This example demonstrates catching the E_CANNOT_WRITE_FILE exception and using session flash messages to inform the user before redirecting them back. This is useful for user-facing error notifications. ```typescript import { errors } from '@jrmc/adonis-attachment' export default class HttpExceptionHandler extends ExceptionHandler { async handle(error: unknown, ctx: HttpContext) { if (error instanceof errors.E_CANNOT_WRITE_FILE) { ctx.session.flash('notification', { type: 'error', message: err.message, }) return ctx.response.redirect('back') } return super.handle(error, ctx) } } ``` -------------------------------- ### Compute URL for a Single User Source: https://adonis-attachment.jrmc.dev/guide/advanced_usage/pre-compile-on-demand.html This example shows how to compute attachment URLs for an individual user record fetched by its ID. ```typescript const user = await User.findOrFail(1) await User.preComputeUrls(user) return user ``` -------------------------------- ### Rendering Picture Component in Vue Source: https://adonis-attachment.jrmc.dev/guide/use-cases/picture-v2.html Usage example for the Vue Picture component, binding the image source and passing the alt text as props. ```vue ``` -------------------------------- ### Configure Autodetect Converter Source: https://adonis-attachment.jrmc.dev/guide/converters/autodetect.html Example of how to configure the autodetect converter in the `config/attachment.ts` file. The autodetect converter is the default and can be explicitly set or left to its default behavior. ```typescript const attachmentConfig = defineConfig({ converters: { large: { // => optional // converter: () => import('@jrmc/adonis-attachment/converters/autodetect_converter'), resize: 1280, } } }) ``` -------------------------------- ### Configure PDF Thumbnail Converter Source: https://adonis-attachment.jrmc.dev/guide/converters/pdf-thumbnail.html Configure the PDF thumbnail converter to use the default settings. This snippet shows the basic setup in the attachment configuration file. ```typescript // config/attachment.ts // const attachmentConfig = defineConfig({ converters: { preview: { converter: () => import('@jrmc/adonis-attachment/converters/pdf_thumbnail_converter'), } } }) ``` -------------------------------- ### Convert Animated GIF to WebP Source: https://adonis-attachment.jrmc.dev/guide/advanced_usage/custom-converter.html This converter uses the Sharp library to transform an animated GIF into a WebP format, preserving metadata like loop and delay. Ensure Sharp is installed. ```typescript import type { ConverterAttributes } from '@jrmc/adonis-attachment/types/converter' import type { Input } from '@jrmc/adonis-attachment/types/input' import Converter from '@jrmc/adonis-attachment/converters/converter' import sharp from 'sharp' export default class Gif2WebpConverter extends Converter { async handle({ input }: ConverterAttributes): Promise { const sharpImage = sharp(input, { animated: true, pages: -1 }) const imageMeta = await sharpImage.metadata() const { loop, delay } = imageMeta const options = { webp: { loop, delay, } } const buffer = await sharpImage .withMetadata() .webp(options.webp) .toBuffer() return buffer } } ``` -------------------------------- ### Listen to Variant Started Event Source: https://adonis-attachment.jrmc.dev/guide/advanced_usage/events.html Register a listener for the 'attachment:variant_started' event to track the beginning of variant generation. This snippet shows how to log basic information about the process. ```typescript // start/attachment.ts import emitter from '@adonisjs/core/services/emitter' import type { AttachmentEventPayload } from '@jrmc/adonis-attachment/types/event' emitter.on('attachment:variant_started', (payload: AttachmentEventPayload) => { console.log(`Started generating variants for ${payload.tableName}.${payload.attributeName}`) console.log(`Record ID: ${payload.primary.value}`) console.log(`Variants: ${payload.variants?.join(', ')}`) }) ``` -------------------------------- ### URL Management Methods Source: https://adonis-attachment.jrmc.dev/guide/basic_usage/attachment-object.html Methods for managing file URLs, including getting regular and signed URLs for files and their variants. ```APIDOC ## URL Management Methods ### Description Methods for managing file URLs, including getting regular and signed URLs for files and their variants. ### Methods #### `getUrl(variantName?: string): Promise` Gets the file URL or a variant URL. #### `getSignedUrl(variantNameOrOptions?: string | SignedURLOptions, signedUrlOptions?: SignedURLOptions): Promise` Gets a signed URL. ### Usage Examples ```typescript // Getting the URL const url = await attachment.getUrl(); // Getting a variant URL const variantUrl = await attachment.getUrl('thumbnail'); // Getting a signed URL const signedUrl = await attachment.getSignedUrl({ expiresIn: '30m' }); // Getting a signed URL for a variant const signedVariantUrl = await attachment.getSignedUrl('thumbnail', { expiresIn: '30m' }); ``` ``` -------------------------------- ### Get Attachment Content as Buffer Source: https://adonis-attachment.jrmc.dev/guide/basic_usage/attachment-object.html Retrieve the attachment's content as a Node.js Buffer. Buffers are efficient for handling binary data. ```typescript const buffer = await attachment.getBuffer(); ``` -------------------------------- ### Vue Component with Picture Variants Source: https://adonis-attachment.jrmc.dev/guide/use-cases/picture-v2.html A Vue.js component using the `