Uploading Files to NetSuite File Cabinet
Learn how to upload files to NetSuite's File Cabinet using Abstra connectors.
Prerequisites
- NetSuite connector configured with
fileCabinetresource enabled - Basic Python knowledge
Basic File Upload
Upload a file with minimal configuration:
from abstra.connectors import run_connection_action
import base64
# Read and encode file
with open("document.pdf", "rb") as f:
file_content = base64.b64encode(f.read()).decode('utf-8')
# Upload to NetSuite
result = run_connection_action(
"netsuite",
"add_file",
{
"name": "document.pdf",
"content": file_content,
"fileType": "PDF"
}
)
file_id = result['data']['id']
print(f"✓ Uploaded file ID: {file_id}")
Upload to Specific Folder
# Upload to SuiteScripts folder
result = run_connection_action(
"netsuite",
"add_file",
{
"name": "my_script.js",
"content": file_content,
"fileType": "JAVASCRIPT",
"folder": {"name": "SuiteScripts"}
}
)
# Upload to SuiteFiles (default)
result = run_connection_action(
"netsuite",
"add_file",
{
"name": "report.xlsx",
"content": file_content,
"fileType": "EXCEL",
"folder": {"name": "SuiteFiles"} # Optional - this is the default
}
)
Supported File Types
| File Type | Parameter Value | Extensions |
|---|---|---|
PDF | ||
| Excel | EXCEL | .xls, .xlsx |
| Word | WORD | .doc, .docx |
| Plain Text | PLAINTEXT | .txt |
| JavaScript | JAVASCRIPT | .js |
| CSV | CSV | .csv |
| PNG Image | PNGIMAGE | .png |
| JPEG Image | JPGIMAGE | .jpg, .jpeg |
Best Practices
File Naming
Use descriptive names with dates:
from datetime import datetime
# Good naming
filename = f"invoice_vendor123_{datetime.now().strftime('%Y%m%d')}.pdf"
filename = f"report_q4_2025_final.xlsx"
# Avoid generic names
# ❌ "document.pdf"
# ❌ "file1.xlsx"
Error Handling
Always wrap uploads in try-except:
import base64
def upload_file_safely(file_path, file_type):
try:
with open(file_path, "rb") as f:
content = base64.b64encode(f.read()).decode('utf-8')
# Check file size (10MB limit)
size_mb = len(content) * 0.75 / (1024 * 1024)
if size_mb > 10:
return {"error": f"File too large: {size_mb:.2f}MB (max 10MB)"}
result = run_connection_action(
"netsuite",
"add_file",
{
"name": file_path.split('/')[-1],
"content": content,
"fileType": file_type
}
)
return {"success": True, "file_id": result['data']['id']}
except FileNotFoundError:
return {"error": f"File not found: {file_path}"}
except Exception as e:
return {"error": f"Upload failed: {str(e)}"}
# Usage
result = upload_file_safely("invoice.pdf", "PDF")
if "error" in result:
print(f"❌ {result['error']}")
else:
print(f"✓ Uploaded: {result['file_id']}")
Batch Uploads
Upload multiple files:
import os
import base64
from pathlib import Path
def upload_directory(directory_path, file_type="PDF"):
uploaded_files = []
for filename in os.listdir(directory_path):
if not filename.endswith('.pdf'):
continue
file_path = os.path.join(directory_path, filename)
with open(file_path, "rb") as f:
content = base64.b64encode(f.read()).decode('utf-8')
result = run_connection_action(
"netsuite",
"add_file",
{
"name": filename,
"content": content,
"fileType": file_type
}
)
uploaded_files.append({
"name": filename,
"id": result['data']['id']
})
print(f"✓ Uploaded: {filename} (ID: {result['data']['id']})")
return uploaded_files
# Usage
uploaded = upload_directory("./invoices", "PDF")
print(f"\n✓ Uploaded {len(uploaded)} files")
Troubleshooting
"File size exceeds limit"
NetSuite SOAP API has a 10MB limit:
import os
file_size_mb = os.path.getsize("large_file.pdf") / (1024 * 1024)
if file_size_mb > 10:
print(f"❌ File too large: {file_size_mb:.2f}MB")
else:
# Proceed with upload
pass
"Invalid file type"
Ensure file type matches content:
# ✅ Correct
run_connection_action("netsuite", "add_file", {
"name": "report.pdf",
"fileType": "PDF" # Matches .pdf extension
})
# ❌ Incorrect
run_connection_action("netsuite", "add_file", {
"name": "report.pdf",
"fileType": "PLAINTEXT" # Wrong type for PDF
})
Base64 encoding errors
Always use binary mode:
# ✅ Correct - binary mode "rb"
with open("file.pdf", "rb") as f:
content = base64.b64encode(f.read()).decode('utf-8')
# ❌ Incorrect - text mode "r"
with open("file.pdf", "r") as f:
content = base64.b64encode(f.read()).decode('utf-8')