Skip to Content
Attachments

Attachments

Getting started

Add your first attachments to Uplo. For example, we will add avatar for User and multiple images for Post.

const uplo = Uplo({ // ... other Uplo config attachments: { user: { avatar: true, // pass true to use default options }, post: { images: { multiple: true } } } })

Options

  • multiple = false (optional): Specify for multiple attachment support on a single record.
  • serviceName (optional): You can provide a custom service.
  • directUpload = true (optional): You can disable direct uploads for specific attachments if needed.

Find attachment

Find an attachment by specifying User ID.

Single

const attachment = await uplo.attachments.user(123).avatar.findOne() console.log(attachment.blob.url());

Multiple

const attachments = await uplo.attachments.post(456).images.findMany()

Detach attachment

Detach an attachment from a record.

Single

const attachment = await uplo.attachments.user(123).avatar.detach()

Multiple

Detach one attachment.

const attachments = await uplo.attachments.post(456).images.detach(attachmentId)

Detach all attachments.

const attachments = await uplo.attachments.post(456).images.detachMany()

Attach file

Attach a file from a file path.

import { blobFileInput } from '@uplo/node' const fileInput = await blobFileInput({ path: '/home/images/image.png', // contentType: 'image/png', // Optional // fileName: 'image.png' // Optional }) const attachment = await uplo.attachments.user(123).avatar.attachFile(fileInput)

Attach a file with string.

import { blobStringInput } from '@uplo/node' const fileInput = await blobStringInput({ content: 'Hello', contentType: 'text/plain', fileName: 'welcome.txt' }) const attachment = await uplo.attachments.user(123).avatar.attachFile(fileInput)

Attach a file with buffer.

import { blobBufferInput } from '@uplo/node' const fileInput = await blobBufferInput({ buffer, contentType: 'text/plain', fileName: 'welcome.txt' }) const attachment = await uplo.attachments.user(123).avatar.attachFile(fileInput)

Attach signed file

If you use direct uploads, you get a Signed ID. You need to manually attach a Signed ID to your records. How to get a Signed ID, please view Client documentation.

const signedId = req.params['signedId'] const attachment = await uplo.attachments.user(123).avatar.attachSignedFile(signedId)
Last updated on