{"record":{"id":"90deef19fbcdb618","repo":"ATH-MaaS/Pixelle-Video","slug":"failed-to-upload-file-response-text","errorCode":null,"errorMessage":"Failed to upload file: {response.text}","messagePattern":"Failed to upload file: (.+?)","errorType":"http","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/image_processor.py","lineNumber":335,"sourceCode":"        with open(file_path, 'rb') as file:\n            files = {\n                'OSSAccessKeyId': (None, policy_data['oss_access_key_id']),\n                'Signature': (None, policy_data['signature']),\n                'policy': (None, policy_data['policy']),\n                'x-oss-object-acl': (None, policy_data['x_oss_object_acl']),\n                'x-oss-forbid-overwrite': (None, policy_data['x_oss_forbid_overwrite']),\n                'key': (None, key),\n                'success_action_status': (None, '200'),\n                'file': (safe_file_name, file)\n            }\n            \n            response = requests.post(\n                policy_data['upload_host'],\n                files=files,\n                proxies=self._proxies(),\n            )\n            if response.status_code != 200:\n                raise Exception(f\"Failed to upload file: {response.text}\")\n        \n        # Construct OSS URL correctly: oss://<bucket>/<key>\n        # Extract bucket from upload_host (e.g., https://dashscope-instant.oss-cn-beijing.aliyuncs.com)\n        upload_host = policy_data['upload_host']\n        bucket_name = \"\"\n        if '://' in upload_host:\n            domain = upload_host.split('://')[1]\n            bucket_name = domain.split('.')[0]\n        \n        if bucket_name:\n            return f\"oss://{bucket_name}/{key}\"\n        else:\n            # Fallback if parsing fails (though unlikely for standard OSS hosts)\n            # If the original code's assumption that key was self-sufficient was somehow valid, logic is here.\n            # But normally, oss://<key> is wrong if key doesn't have bucket.\n            return f\"oss://{key}\"\n    \n    def upload(self, file_path: str) -> str:","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/image_processor.py#L317-L353","documentation":"upload_file_to_oss posts the file to the OSS upload_host from the policy and raises Exception on a non-200 status, including the OSS response body. The credentials were obtained, but the actual binary upload to the OSS bucket was rejected.","triggerScenarios":"POST to policy_data['upload_host'] returns non-200: expired upload policy/credentials (they are temporary), missing or wrong form fields (key, policy, signature, OSSAccessKeyId, file), file too large, or OSS endpoint unreachable.","commonSituations":"Reusing a cached policy_data after it expired, constructing the multipart form incorrectly (file must be the last field), proxy interference breaking the OSS upload, uploading before fetching a fresh policy.","solutions":["Check response.text in the error — OSS returns XML explaining the rejection (SignatureDoesNotMatch, AccessDenied, Expired).","Fetch a fresh upload policy immediately before each upload; do not reuse stale policy_data.","Ensure multipart fields exactly match the policy (policy, signature, OSSAccessKeyId, key, success_status) with the file last.","Verify network/proxy settings allow reaching the OSS host (self._proxies() configuration)."],"exampleFix":"// before\npolicy = processor.get_upload_policy()\n# ... long processing ...\nurl = processor.upload_file_to_oss(policy, path)  # policy expired\n\n// after\npolicy = processor.get_upload_policy()  # fetch fresh, upload immediately\nurl = processor.upload_file_to_oss(policy, path)","handlingStrategy":"retry","validationCode":"import os, time\nassert os.path.exists(file_path), \"file missing before OSS upload\"\nassert policy_data and policy_data.get(\"upload_host\"), \"no upload policy — fetch one first\"","typeGuard":"def is_fresh_policy(policy, max_age_s=600) -> bool:\n    return policy is not None and (time.time() - policy.get(\"fetched_at\", 0)) < max_age_s","tryCatchPattern":"try:\n    url = processor.upload_file_to_oss(policy_data, file_path)\nexcept Exception as e:\n    logging.error(f\"OSS upload failed: {e}\")\n    fresh = processor.get_upload_policy()  # policy may have expired\n    url = processor.upload_file_to_oss(fresh, file_path)","preventionTips":["Fetch a fresh policy immediately before each upload; never reuse stale ones","Match multipart form fields exactly (file field last)","Check the OSS XML body in the error for SignatureDoesNotMatch/Expired codes","Verify proxy settings allow direct access to the OSS host"],"tags":["oss","upload","http-error","aliyun"],"backgroundTag":"file-upload-failed","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}