assets.create
Puck Assets is in early access. Request access.
Create an asset from a file.
await puck.assets.create({
filename: "bike.png",
fileData: await readFile("bike.png"),
});Returns the created Asset.
Args
| Param | Example | Type | Status |
|---|---|---|---|
params | { filename: "bike.png" } | Object | Required |
options | { auth: {} } | Object | - |
params
What to create the asset with.
| Param | Example | Type | Status |
|---|---|---|---|
filename | filename: "bike.png" | String | Required |
fileData | fileData: await readFile("bike.png") | Blob | ArrayBuffer | Uint8Array | ReadableStream | AsyncIterable | Required |
sizeBytes | sizeBytes: 5242880 | Number | - |
mediaType | mediaType: "image/png" | String | - |
width | width: 1200 | Number | - |
height | height: 800 | Number | - |
folderId | folderId: "folder_123" | String | - |
title | title: "Red bike" | String | - |
alt | alt: "A red bike" | String | - |
tags | tags: ["Brand"] | String[] | - |
Required params
filename
The file’s name.
fileData
The file’s data, up to 2 GB.
Optional params
sizeBytes
The file’s size in bytes. Required if fileData is a stream.
const asset = await puck.assets.create({
filename: "intro.mp4",
fileData: createReadStream("intro.mp4"),
sizeBytes: (await stat("intro.mp4")).size,
});mediaType
The file’s media type. Defaults to the Blob type, or the type that matches the extension of filename.
const asset = await puck.assets.create({
filename: "bike",
fileData: await readFile("bike.png"),
mediaType: "image/png",
});width
The asset’s width in pixels. Defaults to null.
const asset = await puck.assets.create({
filename: "bike.png",
fileData: await readFile("bike.png"),
width: 1200,
height: 800,
});height
The asset’s height in pixels. Defaults to null.
folderId
The id of the folder to put the asset in. Defaults to no folder.
const asset = await puck.assets.create({
filename: "bike.png",
fileData: await readFile("bike.png"),
folderId: "folder_123",
});title
The asset’s title. Defaults to no title.
alt
The asset’s alt text. Defaults to no alt text.
const asset = await puck.assets.create({
filename: "bike.png",
fileData: await readFile("bike.png"),
title: "Red bike",
alt: "A red bike",
});tags
The asset’s tags, up to 50. Defaults to no tags.
A tag can’t contain a comma.
const asset = await puck.assets.create({
filename: "bike.png",
fileData: await readFile("bike.png"),
tags: ["Brand", "Summer"],
});options
Set the request options for this call.