Generate experiences with Puck AI
Read docs
CloudAPI referencecloud-clientServer APIsassets.create

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

ParamExampleTypeStatus
params{ filename: "bike.png" }ObjectRequired
options{ auth: {} }Object-

params

What to create the asset with.

ParamExampleTypeStatus
filenamefilename: "bike.png"StringRequired
fileDatafileData: await readFile("bike.png")Blob | ArrayBuffer | Uint8Array | ReadableStream | AsyncIterableRequired
sizeBytessizeBytes: 5242880Number-
mediaTypemediaType: "image/png"String-
widthwidth: 1200Number-
heightheight: 800Number-
folderIdfolderId: "folder_123"String-
titletitle: "Red bike"String-
altalt: "A red bike"String-
tagstags: ["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.