Delete a File
Remove files from your account:- CLI
- Python SDK
- JavaScript SDK
Delete by file ID:Delete by filename:Example Output (Delete by ID):Example Output (Delete by filename):
Copy
gravixlayer files delete 977ca95b-0705-4ad2-846e-7d3d15af3eb2
Copy
gravixlayer files delete README.md
Copy
🗑️ Deleting file: 977ca95b-0705-4ad2-846e-7d3d15af3eb2
✅ File deleted successfully!
Copy
🗑️ Deleting file: README.md
Looking up file by name...
Found file ID: a804e4a3-ea8b-4ac7-855b-c7977f9d0ed4
✅ File deleted successfully!
Flexible Delete Options: You can delete files using either the file ID or the filename. When using a filename, the CLI will automatically look up the corresponding file ID.
Copy
import os
from gravixlayer import GravixLayer
client = GravixLayer()
# Delete a file
delete_response = client.files.delete("file-abc123def456")
print(f"File deleted: {delete_response.file_name}")
print(f"Message: {delete_response.message}")
Copy
import { GravixLayer } from 'gravixlayer';
const client = new GravixLayer({
apiKey: process.env.GRAVIXLAYER_API_KEY,
});
async function deleteFile() {
try {
const files = await client.files.list();
if (files.data.length === 0) {
console.log('No files found to delete.');
return;
}
let targetFile = files.data.find(file => file.filename === 'document.pdf');
if (!targetFile) {
targetFile = files.data[0];
}
const deleteResponse = await client.files.delete(targetFile.id);
console.log(`File deleted: ${deleteResponse.file_name}`);
console.log(`Message: ${deleteResponse.message}`);
} catch (error) {
console.error('Delete failed:', error.message);
}
}
deleteFile();
Delete Multiple Files
- Python SDK
- JavaScript SDK
Copy
import os
from gravixlayer import GravixLayer
client = GravixLayer()
# Delete multiple files by ID
file_ids_to_delete = ["708a4c39-d99b-450b-91a3-42513499baf1", "cc470690-1f66-4f09-844b-d0cbeede804b"]
for file_id in file_ids_to_delete:
try:
delete_response = client.files.delete(file_id)
print(f"Deleted: {delete_response.file_id}")
except Exception as e:
print(f"Failed to delete {file_id}: {e}")
# Delete files by purpose
files_response = client.files.list()
temp_files = [f for f in files_response.data if f.purpose == "batch"]
for file in temp_files:
try:
delete_response = client.files.delete(file.id)
print(f"Deleted batch file: {file.filename}")
except Exception as e:
print(f"Failed to delete {file.filename}: {e}")
Copy
import { GravixLayer } from 'gravixlayer';
const client = new GravixLayer({
apiKey: process.env.GRAVIXLAYER_API_KEY,
});
// Delete multiple files by ID
const fileIdsToDelete = ["file-abc123", "file-def456", "file-ghi789"];
for (const fileId of fileIdsToDelete) {
try {
const deleteResponse = await client.files.delete(fileId);
console.log(`Deleted: ${deleteResponse.file_id}`);
} catch (error) {
console.log(`Failed to delete ${fileId}: ${error.message}`);
}
}
// Delete files by purpose
const filesResponse = await client.files.list();
const tempFiles = filesResponse.data.filter(f => f.purpose === "batch");
for (const file of tempFiles) {
try {
const deleteResponse = await client.files.delete(file.id);
console.log(`Deleted batch file: ${file.filename}`);
} catch (error) {
console.log(`Failed to delete ${file.filename}: ${error.message}`);
}
}
Copy
Deleted: 6d9a8af0-376e-4e34-86d6-33e648b9b6de
Deleted: 40548770-462e-461f-b115-47d212600468
Deleted batch file: test1.jpg
Delete Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
file_id | string | Yes | File ID (e.g., 977ca95b-0705-4ad2-846e-7d3d15af3eb2) |

