{"record":{"id":"f1a166ccd100971a","repo":"xtekky/gpt4free","slug":"upload-failed-result","errorCode":null,"errorMessage":"Upload failed: {result}","messagePattern":"Upload failed: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"g4f/Provider/OperaAria.py","lineNumber":253,"sourceCode":"                \"Origin\": \"https://composer.opera-api.com\",\n                \"User-Agent\": cls._user_agent_v2,\n            },\n            data=media_bytes,\n        ) as response:\n            response.raise_for_status()\n\n        # Step 3: Poll for completion\n        for attempt in range(60):\n            async with session.get(\n                f\"{cls.files_endpoint}{file_id}\", headers=headers\n            ) as response:\n                response.raise_for_status()\n                result = await response.json()\n                status = result.get(\"upload_status\")\n                if status == \"finished\":\n                    return file_id\n                if status in (\"failed\", \"error\"):\n                    raise Exception(f\"Upload failed: {result}\")\n            await asyncio.sleep(min(1 + attempt * 0.3, 2))\n\n        raise Exception(f\"Upload timeout for {file_id}\")\n\n    @classmethod\n    async def _process_media(\n        cls,\n        session: ClientSession,\n        access_token: str,\n        media: MediaListType,\n        messages: Messages,\n    ) -> list:\n        \"\"\"Process and upload all media (V2 only).\"\"\"\n        attachments = []\n        for media_data, media_name in merge_media(media, messages):\n            try:\n                if isinstance(media_data, str) and media_data.startswith(\"data:\"):\n                    media_bytes = base64.b64decode(media_data.split(\",\", 1)[1])","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/OperaAria.py#L235-L271","documentation":"Raised during OperaAria (V2 flow) file upload polling when the files endpoint reports upload_status of 'failed' or 'error' for the uploaded file. The provider uploads media, then polls GET {files_endpoint}{file_id} until 'finished'; a terminal failure status aborts with the full JSON body embedded in the message.","triggerScenarios":"Uploading media via OperaAria when Opera's backend rejects or fails processing the file server-side: unsupported format, corrupted bytes, expired access token causing a degraded status, or size limits enforced after initial accept.","commonSituations":"Sending HEIC/txt/other formats Opera cannot process; auth token expired mid-poll (partial failures); flaky upstream storage; media passed both in `media` and embedded in messages causing double-upload conflicts.","solutions":["Read the `result` JSON in the message to identify the server-side failure reason.","Convert media to a widely supported format (jpeg/png/mp4) and re-upload.","Re-run to refresh the access token (tokens are obtained per call); if it persists, update g4f for API changes.","Avoid passing the same media in both the media list and message content."],"exampleFix":"// before\nmedia = [('doc.pdf', open('doc.pdf','rb').read())]\n\n// after - use a supported image format\nmedia = [('photo.png', open('photo.png','rb').read())]","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\nSUPPORTED = {'.png', '.jpg', '.jpeg', '.gif', '.mp4', '.webp'}\n\ndef opera_media_supported(name: str) -> bool:\n    return Path(name).suffix.lower() in SUPPORTED","typeGuard":null,"tryCatchPattern":"try:\n    result = await OperaAria.create_async_generator(model, messages, media=media)\nexcept Exception as e:\n    if 'Upload failed' in str(e):\n        result = await OperaAria.create_async_generator(model, messages)  # retry without media","preventionTips":["Convert media to jpeg/png/mp4 before upload","Inspect embedded result JSON for server-side reason","Refresh access token by restarting the call","Don't duplicate media in both media list and message content"],"tags":["opera","file-upload","media","polling","upstream-api"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}