{"record":{"id":"97e8af8bdc35a57e","repo":"xtekky/gpt4free","slug":"failed-to-upload-file-result","errorCode":null,"errorMessage":"Failed to upload file: {result}","messagePattern":"Failed to upload file: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/DeepSeek.py","lineNumber":236,"sourceCode":"        # Create multipart form data\n        data = FormData()\n        data.add_field(\"file\", file, filename=filename, content_type=\"application/pdf\")\n\n        async with session.post(\n            FILE_UPLOAD_ENDPOINT, data=data, headers={\"accept\": \"application/json\"}\n        ) as response:\n            debug.log(f\"DeepSeekAuth: File upload response status: {response.status}\")\n            await raise_for_status(response)\n            result = await response.json()\n            debug.log(f\"DeepSeekAuth: File upload response: {result}\")\n\n        if \"data\" in result:\n            file_id = result[\"data\"].get(\"id\")\n            debug.log(f\"DeepSeekAuth: File uploaded successfully, file_id: {file_id}\")\n            return {\"file_id\": file_id, \"filename\": filename, \"size\": len(file)}\n        else:\n            debug.error(f\"DeepSeekAuth: Failed to upload file: {result}\")\n            raise Exception(f\"Failed to upload file: {result}\")\n\n    @classmethod\n    async def delete_chat_session(\n        cls, session: StreamSession, chat_session_id: str, headers: dict\n    ):\n        \"\"\"\n        Delete a chat session from DeepSeek.\n\n        Tries multiple approaches (DELETE/POST with JSON body/query params) until one succeeds.\n\n        Args:\n            session: StreamSession instance\n            chat_session_id: The session ID to delete\n            headers: Request headers including authorization\n        \"\"\"\n        import json as json_module\n\n        # Try different deletion approaches - POST with JSON body first (as seen in HAR)","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/DeepSeek.py#L218-L254","documentation":"Generic Exception raised by DeepSeekAuth's file-upload helper: the POST to DeepSeek's file-upload endpoint succeeded at the HTTP level (raise_for_status passed) but the JSON response contains no \"data\" key, so no file id could be extracted. The full response body is embedded in the message via debug logging and the exception.","triggerScenarios":"Attaching media (images/files) to a DeepSeek authenticated chat request and the upload API returns an error payload or unexpected schema — e.g. unsupported file type, file too large, auth token accepted for chat but rejected for uploads, or DeepSeek changed the response shape.","commonSituations":"Uploading files over the size/format limit; expired or partially-scoped HAR token; DeepSeek backend change; empty file passed as media.","solutions":["Inspect the {result} payload in the message — it usually contains the upstream reason (format, size, permission).","Retry with a supported file type and a smaller file.","Re-export a fresh HAR file so the auth token is fully valid for upload endpoints.","If the schema changed, update g4f to the latest version."],"exampleFix":"# before\nresp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs, media=[\"huge_video.mp4\"])\n# Exception: Failed to upload file: {'code': 413}\n\n# after\nresp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs, media=[\"photo.jpg\"])","handlingStrategy":"try-catch","validationCode":"def media_uploadable(paths):\n    allowed = {\".jpg\", \".jpeg\", \".png\", \".webp\", \".pdf\", \".txt\", \".docx\"}\n    return all(Path(p).suffix.lower() in allowed and Path(p).stat().st_size < 50 * 1024 * 1024 for p in paths)","typeGuard":null,"tryCatchPattern":"try:\n    resp = await client.chat.completions.create(model=m, provider=DeepSeek, messages=msgs, media=files)\nexcept Exception as e:\n    if \"Failed to upload file\" in str(e):\n        shrink_or_convert_media(files)","preventionTips":["Validate file type/size before attaching media.","Keep the HAR token fresh so upload endpoints accept it.","Log the response payload embedded in the exception — it names the cause."],"tags":["file-upload","deepseek","media","response-parsing"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}