{"record":{"id":"da7d4af4a810b507","repo":"iflytek/astron-agent","slug":"23601-file-name-cannot-be-empty","errorCode":"23601","errorMessage":"File name cannot be empty","messagePattern":"File name cannot be empty","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"warning","filePath":"core/workflow/api/v1/flow/file.py","lineNumber":49,"sourceCode":"async def upload_file(\n    x_consumer_username: Annotated[str, Header()], file: UploadFile = File(...)\n) -> JSONResponse:\n    \"\"\"\n    Upload a single file to the workflow system.\n\n    :param x_consumer_username: Consumer username from header\n    :param file: File to upload\n    :return: Response with uploaded file URL\n    \"\"\"\n    app_id = x_consumer_username\n    m = Meter(app_id)\n    span = Span(app_id=app_id)\n    with span.start() as span_context:\n        try:\n            contents = await file.read()\n            file_service.check(file, contents, span_context)\n            if not file.filename:\n                raise CustomException(\n                    err_code=CodeEnum.FILE_INVALID_ERROR,\n                    err_msg=\"File name cannot be empty\",\n                )\n            extension = file.filename.split(\".\")[-1].lower()\n            file_url = await get_oss_service().upload_file_async(\n                f\"{str(uuid.uuid4())}.{extension}\", contents\n            )\n            m.in_success_count()\n            return Resp.success(data={\"url\": file_url}, sid=span_context.sid)\n        except CustomException as e:\n            span_context.record_exception(e)\n            m.in_error_count(e.code, span=span_context)\n            return Resp.error(e.code, e.message, span_context.sid)\n        except Exception as e:\n            span_context.record_exception(e)\n            m.in_error_count(CodeEnum.FILE_STORAGE_ERROR.code, span=span_context)\n            return Resp.error(\n                CodeEnum.FILE_STORAGE_ERROR.code,","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/api/v1/flow/file.py#L31-L67","documentation":"upload_file in the flow file API rejects an UploadFile whose filename is empty/None (code 23601, FILE_INVALID_ERROR). After reading bytes and running file_service.check, it validates the filename because the extension is derived from filename.split('.')[-1] and an empty name cannot produce a valid storage key.","triggerScenarios":"POSTing multipart/form-data to the flow file upload endpoint with a file part lacking a filename (no filename in Content-Disposition), or with filename set to empty string.","commonSituations":"HTTP clients that send raw bytes without a proper multipart filename field; programmatic uploads (curl --data-binary instead of -F); generated file parts from tests/scripts omitting the filename; proxies stripping Content-Disposition metadata.","solutions":["Ensure the multipart part includes a filename, e.g. curl -F 'file=@report.pdf' instead of raw body upload.","Validate the filename client-side before upload and reject empty names with a friendly message.","If uploading programmatically, set the filename explicitly in your HTTP client's form builder.","Sanitize/derive a fallback filename server-side before the check if empty names are acceptable in your flow."],"exampleFix":"# before\ncurl --data-binary @report.pdf http://host/api/v1/flow/file/upload\n\n# after\ncurl -F 'file=@report.pdf' http://host/api/v1/flow/file/upload","handlingStrategy":"validation","validationCode":"if not file or not getattr(file, 'filename', None):\n    raise ValueError(\"file must have a non-empty filename before upload\")","typeGuard":"def has_filename(file) -> bool:\n    return bool(getattr(file, 'filename', None))","tryCatchPattern":"try:\n    await upload_file(file)\nexcept CustomException as e:\n    if e.code == CodeEnum.FILE_INVALID_ERROR.code:\n        show_user_error(\"Please select a valid file with a name\")\n    else:\n        raise","preventionTips":["Always upload via multipart form fields with an explicit filename (curl -F, FormData)","Validate filename presence/extension client-side before sending","Check Content-Disposition is not stripped by proxies/gateways"],"tags":["upload","validation","multipart","filename"],"backgroundTag":"empty-required-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}