Attachment Object
The Attachment object is the main class that handles attached files in your application.
Properties
Base Properties
drive
: Drive service used for file managementname
: File nameoriginalName
: Original file namefolder
: Storage folderpath
: Complete file pathsize
: File size in bytesextname
: File extensionmimeType
: File MIME typemeta
: File metadata (EXIF)originalPath
: Original file pathurl
: File URLvariants
: Array of file variants
Methods
URL Management
getUrl(variantName?: string): Promise<string>
: Gets the file URL or a variant URLgetSignedUrl(variantNameOrOptions?: string | SignedURLOptions, signedUrlOptions?: SignedURLOptions): Promise<string>
: Gets a signed URL
File Management
getDisk(): Disk
: Gets the storage diskgetBytes(): Promise<Uint8Array>
: Gets file content as bytesgetBuffer(): Promise<Buffer>
: Gets file content as buffergetStream(): Promise<NodeJS.ReadableStream>
: Gets file content as stream
Usage Examples
URL Management
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'
});
File Management
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'));