You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ChatGPT自定义GPT4应用OpenAPI Schema上传S3二进制文件异常求助

自定义GPT4应用S3文件上传异常排查与解决

问题背景

开发自定义GPT4应用时,通过OpenAPI Schema配置PUT接口上传PDF/Word等二进制文件到S3桶,API连接成功但S3中文件为空或仅含元数据。示例请求体如下:

{"metadata": {"name": "Manual", "description": "A comprehensive manual for Capri, including important contact numbers, other information, instructions, recommendations, and FAQs."}, "fileData": "/mnt/data/test.pdf"}

用Postman测试API返回200且文件正常,但导入OpenAPI Schema后出现异常。当前使用的OpenAPI Schema代码如下:

{"openapi": "3.1.0","info": {"title": "S3 Bucket File Management API","version": "1.0.0"},"servers": [{"url": "https://HIDDEN.execute-api.us-east-1.amazonaws.com/prod"}],"paths": {"/bnb-bucket-ham/{filename}": {"put": {"summary": "Upload a file to the S3 bucket","operationId": "uploadFile","parameters": [{"name": "filename","in": "path","required": true,"schema": {"type": "string"}}],"requestBody": {"required": true,"content": {"application/json": {"schema": {"type": "object","properties": {"metadata": {"type": "object","properties": {"name": {"type": "string"},"description": {"type": "string"}},"required": ["name"]},"fileData": {"type": "string","format": "byte"}},"required": ["metadata", "fileData"]}},"application/pdf": {},"application/msword": {},"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {}}},"responses": {"200": {"description": "File uploaded successfully"}}},"get": {"summary": "Retrieve a file from the S3 bucket","operationId": "getFile","parameters": [{"name": "filename","in": "path","required": true,"schema": {"type": "string"}}],"responses": {"200": {"description": "File retrieved successfully","content": {"application/pdf": {"schema": {"type": "string","format": "binary"}},"application/msword": {"schema": {"type": "string","format": "binary"}},"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {"schema": {"type": "string","format": "binary"}}}},"404": {"description": "File not found"}}}}}

可行性判断

需求完全可行,问题出在OpenAPI Schema的定义与GPT4自定义应用的文件上传逻辑不匹配,导致文件内容未被正确编码传输。

解决方法

  • 修正请求体内容类型与结构:原Schema混合定义JSON和二进制内容类型,GPT4调用时可能误传文件路径而非二进制内容。改用multipart/form-data格式,同时支持元数据和二进制文件上传,这是文件上传的标准流程:
    "requestBody": {
      "required": true,
      "content": {
        "multipart/form-data": {
          "schema": {
            "type": "object",
            "properties": {
              "metadata": {
                "type": "object",
                "properties": {
                  "name": {"type": "string"},
                  "description": {"type": "string"}
                },
                "required": ["name"]
              },
              "fileData": {
                "type": "string",
                "format": "binary"
              }
            },
            "required": ["metadata", "fileData"]
          }
        }
      }
    }
    
  • 移除冗余配置:原Schema中单独定义的application/pdf、application/msword等内容类型未指定schema,属于无效配置,会导致GPT4混淆请求格式,直接删除这些条目。
  • 适配后端处理逻辑:确认AWS Lambda或后端服务支持multipart/form-data请求,能正确解析元数据和二进制文件流,再将文件内容写入S3桶。若之前仅支持JSON格式,需修改后端代码处理multipart请求。
  • 明确调用提示:在Schema的summary或description中补充说明:需将文件内容以二进制形式作为fileData字段上传,同时附带metadata对象,避免GPT4误传文件路径。

内容的提问来源于stack exchange,提问作者Hamoun Karami

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 03:28:28