Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace attachmentsService

Helper functions for attachment handling

import { attachmentsService } from '@oneblink/apps'

Index

Type aliases

AttachmentBase: { _id: string; data?: Blob; fileName: string; isPrivate: boolean }

Type declaration

  • _id: string
  • Optional data?: Blob
  • fileName: string
  • isPrivate: boolean
AttachmentError: AttachmentBase & { errorMessage: string; type: "ERROR" }
AttachmentNew: AttachmentBase & { type: "NEW" }
AttachmentSaved: SubmissionTypes.FormSubmissionAttachment & { type?: undefined }
AttachmentUnsaved: AttachmentNew | AttachmentError
FormElementKey: string

The form element name for accessing its submission data

FormSubmissionModel: Record<FormElementKey, unknown>

The submission data model to be submitted

SubmissionAttachmentDetail: { needsToUpload: true; value: AttachmentUnsaved } | { needsToUpload: false; value: AttachmentSaved }
UploadAttachmentConfiguration: { contentType?: string; data: Blob; fileName: string; formId: number; isPrivate: boolean; onProgress?: ProgressListener }

Type declaration

  • Optional contentType?: string
  • data: Blob
  • fileName: string
  • formId: number
  • isPrivate: boolean
  • Optional onProgress?: ProgressListener

Functions

  • Upload a submission attachment. Attachment can be passed as a Blob, Uint8Array or string (base64). Will return data required form accessing the attachment.

    Example

    const blob = new Blob(['a string of data'], {
    type: 'text/plain',
    })
    const file = {
    formId: 1,
    data: blob,
    fileName: 'file.jpg',
    contentType: 'image/jpeg',
    isPrivate: true, // Whether the attachment will be able to be downloaded by other users
    }
    const abortController = new AbortController()
    const {
    s3: {
    key, // string
    bucket, // string
    region, // string
    },
    url, // string
    contentType, // string
    fileName, // string
    id, //string
    isPrivate, // boolean
    uploadedAt, // string
    } = await submissionService.uploadAttachment(
    file,
    abortController.signal,
    )

    Parameters

    Returns Promise<FormSubmissionAttachment>