A helper class for handling files in contrail. For uploading files, we recommend using the createAndUploadFileFromBuffer method for most use cases.

Once a file is uploaded, the download link is stored in the downloadUrl property of the returned file object. The download url is valid for 24 hours. If you wish to refresh the download url, you can fetch the file entity again, using its id. This assumes that you've stored the file ID.

const freshFileEntity = await new Entities().get({entityName: 'file', id: storedFileId});
const freshDownloadUrl = freshFileEntity.downloadUrl;

Constructors

  • Parameters

    • Optional ctx: any

    Returns Files

Properties

ctx: any

Methods

  • Parameters

    • uploadPost: any
    • formData: any

    Returns void

  • Parameters

    • file: File
    • ownedByReference: string = null
    • ttl: number = null

    Returns Promise<any>

  • Uploads a file using a buffer.

    Example Usage:

    const alphabet = {a: 1, b: 2, c: 3}
    const fileBuffer = Buffer.from(alphabet, 'utf-8');
    const fileName = 'alphabet.json';
    const uploadFile = await new Files().createAndUploadFileFromBuffer(fileBuffer, 'text/json', fileName, null, 24 * 60 * 60 * 1000);

    Parameters

    • buffer: any

      The buffer of the object to upload. Can be created by Buffer.from(theObject, 'utf-8')

    • contentType: string

      The content type of the file. Example: 'text/json', 'image/png', 'image/jpeg', or 'application/pdf'

    • fileName: string

      The name of the file

    • ownedByReference: string = null

      The entity reference that owns this file.

    • ttl: number = null

      The time to live of this file (in milliseconds)

    Returns Promise<any>

    The file entity that was created.

Generated using TypeDoc