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
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/info \
--header 'Authorization: Bearer <token>'{
"type": "file",
"name": "example.txt",
"path": "/path/to/example.txt",
"size": "10MB",
"mode": "755",
"lastModified": "2021-01-01T00:00:00Z"
}File System
Get file/dir
Retrieves metadata for a specific file or directory inside a box
GET
/
boxes
/
{boxId}
/
fs
/
info
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
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/info \
--header 'Authorization: Bearer <token>'{
"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
Example:
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Query Parameters
Working directory. If not provided, the file will be read from the box.config.workingDir directory.
Example:
"/home/user/documents"
Target path in the box. If the path does not start with '/', the file/directory will be checked relative to the working directory
Example:
"/home/user/documents/output.txt"
Response
Get file/dir
- File
- Directory
File system file representation
File type indicator
Available options:
file Name of the file
Example:
"example.txt"
Full path to the file in the box
Example:
"/path/to/example.txt"
Size of the file
Example:
"10MB"
File metadata
Example:
"755"
Last modified time of the file
Example:
"2021-01-01T00:00:00Z"
Was this page helpful?