JavaScript
import GboxSDK, { isFileOperator } 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" });
// prepare: write a file
await box.fs.write({
path: "/tmp/example.txt",
content: "Hello, world!",
});
// example: read a file/directory
const file = await box.fs.get({
path: "/tmp/example.txt",
});
if (isFileOperator(file)) {
const { content } = await file.read();
console.info(`๐ ${file.data.name} (${file.data.size}) - ${file.data.path}`);
console.info(`content: ${content}`);
} else {
console.info(`๐ ${file.data.name} - ${file.data.path} is a directory`);
}
}
main();import os
import json
from gbox_sdk import GboxSDK
from gbox_sdk.utils import is_file_operator
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# prepare: write a file
box.fs.write(
path="/tmp/example.txt",
content="Hello, world!"
)
# example: read a file/directory
file = box.fs.get(
path="/tmp/example.txt"
)
if is_file_operator(file):
content = file.read()
print(f"๐ {file.data.name} ({file.data.size}) - {file.data.path}")
print(f"content: {content}")
else:
print(f"๐ {file.data.name} - {file.data.path} is a directory")
if __name__ == "__main__":
main()curl --request GET \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/read \
--header 'Authorization: Bearer <token>'{
"content": "{\n \"name\": \"My Project\",\n \"version\": \"1.0.0\"\n}"
}File System
Read box file
Reads the contents of a file inside the box and returns it as a string. Supports absolute or relative paths, with workingDir as the base for relative paths.
GET
/
boxes
/
{boxId}
/
fs
/
read
JavaScript
import GboxSDK, { isFileOperator } 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" });
// prepare: write a file
await box.fs.write({
path: "/tmp/example.txt",
content: "Hello, world!",
});
// example: read a file/directory
const file = await box.fs.get({
path: "/tmp/example.txt",
});
if (isFileOperator(file)) {
const { content } = await file.read();
console.info(`๐ ${file.data.name} (${file.data.size}) - ${file.data.path}`);
console.info(`content: ${content}`);
} else {
console.info(`๐ ${file.data.name} - ${file.data.path} is a directory`);
}
}
main();import os
import json
from gbox_sdk import GboxSDK
from gbox_sdk.utils import is_file_operator
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# prepare: write a file
box.fs.write(
path="/tmp/example.txt",
content="Hello, world!"
)
# example: read a file/directory
file = box.fs.get(
path="/tmp/example.txt"
)
if is_file_operator(file):
content = file.read()
print(f"๐ {file.data.name} ({file.data.size}) - {file.data.path}")
print(f"content: {content}")
else:
print(f"๐ {file.data.name} - {file.data.path} is a directory")
if __name__ == "__main__":
main()curl --request GET \
--url https://gbox.ai/api/v1/boxes/{boxId}/fs/read \
--header 'Authorization: Bearer <token>'{
"content": "{\n \"name\": \"My Project\",\n \"version\": \"1.0.0\"\n}"
}Authorizations
Enter your API Key in the format: Bearer . Get it from https://gbox.ai
Query Parameters
Was this page helpful?