Skip to content

Automate browser based workflows with AI

Implement upload_file endpoint (#548)

Kerem Yilmaz0a11e225d674
diff --git a/skyvern/forge/sdk/routes/agent_protocol.py b/skyvern/forge/sdk/routes/agent_protocol.py
index 7fc8d4afc..84cd3705d 100644
--- a/skyvern/forge/sdk/routes/agent_protocol.py
+++ b/skyvern/forge/sdk/routes/agent_protocol.py
@@ -753,8 +753,14 @@ async def update_organization(
async def validate_file_size(file: UploadFile) -> UploadFile:
- # Check the file size
- if file.size > app.SETTINGS_MANAGER.MAX_UPLOAD_FILE_SIZE:
+ try:
+ file.file.seek(0, 2) # Move the pointer to the end of the file
+ size = file.file.tell() # Get the current position of the pointer, which represents the file size
+ file.file.seek(0) # Reset the pointer back to the beginning
+ except Exception as e:
+ raise HTTPException(status_code=500, detail="Could not determine file size.") from e
+
+ if size > app.SETTINGS_MANAGER.MAX_FILE_SIZE:
raise HTTPException(
status_code=413,
detail=f"File size exceeds the maximum allowed size ({app.SETTINGS_MANAGER.MAX_UPLOAD_FILE_SIZE} bytes)",