Skip to main content

Processing Storage

Storage operations are performed using ductape.processor.storage.run(data).

This method processes storage-related requests such as uploading files within the Ductape system, using environment, product tag, and other parameters.

await ductape.processor.storage.run(data: IStorageProcessorInput)

This processes a storage event in the specified environment and application context, passing along file data, metadata, and optionally session tracking.

Parameters

IStorageProcessorInput

FieldTypeRequiredDescription
envstringYesEnvironment slug (e.g., "dev", "prd").
product_tagstringYesUnique identifier for the product.
eventstringYesTag of the storage event to be triggered.
inputIStorageRequestYesFile data and metadata for storage.
sessionISessionNoAttach user session context to the request.
cachestringNoCache tag to cache this request, if applicable.
retriesnumberNoNumber of retry attempts on failure.

Note: Optional fields can be omitted or passed as empty {}.

IStorageRequest

The shape of the input object:

interface IStorageRequest {
buffer: string; // Base64-encoded file content
fileName: string; // Name of the file
mimeType?: string; // MIME type of the file (optional)
}
FieldTypeRequiredDescription
bufferstringYesBase64-encoded content of the file.
fileNamestringYesName of the file.
mimeTypestringNoMIME type of the file. Inferred if omitted.

ISession Schema

The session field enables optional session tracking for any storage operation.

interface ISession {
tag: string; // session tag
token: string; // session token (e.g. signed JWT)
}
FieldTypeRequiredDescription
tagstringYesTag identifying the session type.
tokenstringYesToken generated when the session was created.

Returns

Returns a Promise<unknown> resolving with the result of the storage operation. The exact structure depends on the specific storage action.

Example

const { buffer, fileName, mimeType } = await ductape.processor.storage.readFile('path/to/file.txt');

const data = {
env: "dev",
product_tag: "my-product",
event: "upload_file",
input: {
buffer,
fileName,
mimeType,
},
session: {
tag: "user-session",
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
},
retries: 2,
cache: "upload-file-cache", // Optional caching
};

const res = await ductape.processor.storage.run(data);

See Also