Hierarchy
- FileField
Methods
create
-
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
-
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
-
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[]>
Description of the TFile type field