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();import os
import json
from gbox_sdk import GboxSDK
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# Write a text file
new_file = box.fs.write(
path="/home/user/example.txt",
content="Hello, World!\nThis is a test file created with GboxSDK."
)
print(f"Write result:")
print(f" File: {new_file.data.name}")
print(f" Path: {new_file.data.path}")
print(f" Size: {new_file.data.size}")
print(f" Mode: {new_file.data.mode}")
print(f" Last Modified: {new_file.data.last_modified}")
# Create a JSON configuration file
config = {
"name": "My Application",
"version": "1.0.0",
"settings": {
"debug": True,
"port": 3000
}
}
box.fs.write(
path="/home/user/config.json",
content=json.dumps(config, indent=2)
)
print("Configuration file created successfully")
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/write \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form path=/home/user/documents/output.txt \
--form 'content=Hello, World!
This is file content.' \
--form 1.content='@example-file'{
"type": "file",
"name": "example.txt",
"path": "/path/to/example.txt",
"size": "10MB",
"mode": "755",
"lastModified": "2021-01-01T00:00:00Z"
}Write box file
Creates or overwrites a file. Creates necessary directories in the path if they don’t exist. If the target path already exists, the write will fail.
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();import os
import json
from gbox_sdk import GboxSDK
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# Write a text file
new_file = box.fs.write(
path="/home/user/example.txt",
content="Hello, World!\nThis is a test file created with GboxSDK."
)
print(f"Write result:")
print(f" File: {new_file.data.name}")
print(f" Path: {new_file.data.path}")
print(f" Size: {new_file.data.size}")
print(f" Mode: {new_file.data.mode}")
print(f" Last Modified: {new_file.data.last_modified}")
# Create a JSON configuration file
config = {
"name": "My Application",
"version": "1.0.0",
"settings": {
"debug": True,
"port": 3000
}
}
box.fs.write(
path="/home/user/config.json",
content=json.dumps(config, indent=2)
)
print("Configuration file created successfully")
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/write \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form path=/home/user/documents/output.txt \
--form 'content=Hello, World!
This is file content.' \
--form 1.content='@example-file'{
"type": "file",
"name": "example.txt",
"path": "/path/to/example.txt",
"size": "10MB",
"mode": "755",
"lastModified": "2021-01-01T00:00:00Z"
}Authorizations
Enter your API Key in the format: Bearer . Get it from https://gbox.ai
Path Parameters
Box ID
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Body
- Write File
- Write File By Binary
Request parameters for writing content to a file
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.
"/home/user/documents/output.txt"
Content of the file (Max size: 512MB)
"Hello, World!\nThis is file content."
Working directory. If not provided, the file will be read from the box.config.workingDir directory.
"/home/user/documents"
Response
Write file
File system file representation
File type indicator
file Name of the file
"example.txt"
Full path to the file in the box
"/path/to/example.txt"
Size of the file
"10MB"
File metadata
"755"
Last modified time of the file
"2021-01-01T00:00:00Z"
Was this page helpful?