Node.js - bucket.file.write()

This is reference documentation for the Nitric Node.js SDK. To learn about Buckets and Storage in Nitric start with the Storage docs.

Write a file to a bucket.

import { bucket } from '@nitric/sdk'
const assets = bucket('assets').allow('write')
const logo = assets.file('images/logo.png')
const imageData = new Uint8Array([
/* image data */
])
try {
await logo.write(imageData)
console.log('Logo written successfully')
} catch (error) {
console.error('Error writing logo:', error)
}

Parameters

  • Name
    data
    Required
    Required
    Type
    Uint8Array
    Description

    The data to write to the file.

Examples

Write a file

import { bucket } from '@nitric/sdk'
const assets = bucket('assets').allow('write')
const txt = assets.file('my-text-file.txt')
const buffer = Buffer.from('My Test File...')
try {
await txt.write(buffer)
console.log('Text file written successfully')
} catch (error) {
console.error('Error writing text file:', error)
}
Last updated on Apr 3, 2025