Hierarchy

  • FileField

Methods

create

  • create(name: string, body: ArrayBuffer): Promise<FileItem>
  • The method creates a file in the process context.

    Parameters

    • name: string

      File name.

    • body: ArrayBuffer

      Body of the file.

      const fileRq = await fetch(`https://jpeg. org/images/jpegsystems-home.jpg`)
      const buf = await fileRq.arrayBuffer()  
      const file = await Context.fields.file.create('home.jpg', buf) 
      

    Returns Promise<FileItem>

createFromLink

  • createFromLink(name: string, url: string): Promise<FileItem>
  • The method uploads a file from an external source to the process context.

    Parameters

    • name: string

      File name.

    • url: string

      Link to a file.

      const file = await Context.fields.file. createFromLink('home.jpg', `https://jpeg.org/images/jpegsystems-home.jpg`)
      

    Returns Promise<FileItem>

createFromStream

  • createFromStream(name: string, stream: ReadableStream): Promise<FileItem>
  • Create a file from the stream in the process context.

    Parameters

    • name: string

      File name.

    • stream: ReadableStream

      File content stream.

      const externalFile = await  fetch(externalURL);
      if (externalFile.body) { 
        const newFile = await  Context.fields.file.createFromStream('home.jpg', externalFile.body) 
      } 
      

    Returns Promise<FileItem>

fetchAll

  • Request all associated files.

    If a field stores multiple links to files, you can request all of them at once:

    const files = await Context.fields.files.fetchAll();
    

    Returns Promise<FileItem[]>