Skip to main content
POST
/
boxes
/
{boxId}
/
fs
/
write
JavaScript
import GboxSDK from "gbox-sdk";

const gboxSDK = new GboxSDK({
  apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
});

async function main() {
  const box = await gboxSDK.create({ type: "linux" });

  // Write a text file
  const newFile = await box.fs.write({
    path: "/home/user/example.txt",
    content: "Hello, World!\nThis is a test file created with GboxSDK.",
  });

  console.log(`Write result: ${JSON.stringify(newFile.data, null, 2)}`);

  // Create a JSON configuration file
  const config = {
    name: "My Application",
    version: "1.0.0",
    settings: {
      debug: true,
      port: 3000,
    },
  };

  await box.fs.write({
    path: "/home/user/config.json",
    content: JSON.stringify(config, null, 2),
  });

  console.log("Configuration file created successfully");
}

main();
{
  "type": "file",
  "name": "example.txt",
  "path": "/path/to/example.txt",
  "size": "10MB",
  "mode": "755",
  "lastModified": "2021-01-01T00:00:00Z"
}

Authorizations

Authorization
string
header
required

Enter your API Key in the format: Bearer <token>. Get it from https://gbox.ai

Path Parameters

boxId
string
required

Box ID

Example:

"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"

Body

multipart/form-data
  • Write File
  • Write File By Binary

Request parameters for writing content to a file

path
string
required

Target path in the box. If the path does not start with '/', the file will be written relative to the working directory. Creates necessary directories in the path if they don't exist. If the target path already exists, the write will fail.

Example:

"/home/user/documents/output.txt"

content
string
required

Content of the file (Max size: 512MB)

Example:

"Hello, World!\nThis is file content."

workingDir
string

Working directory. If not provided, the file will be read from the box.config.workingDir directory.

Example:

"/home/user/documents"

Response

Write file

File system file representation

type
enum<string>
required

File type indicator

Available options:
file
name
string
required

Name of the file

Example:

"example.txt"

path
string
required

Full path to the file in the box

Example:

"/path/to/example.txt"

size
string
required

Size of the file

Example:

"10MB"

mode
string
required

File metadata

Example:

"755"

lastModified
string<date-time>
required

Last modified time of the file

Example:

"2021-01-01T00:00:00Z"

I