多部分文件上传
多部分文件上传
使用 multipart/form-data 内容类型记录端点
多部分文件上传
使用 multipart/form-data 内容类型记录端点
多部分请求将一个或多个数据集组合到单个请求体中,通过边界分隔。 您通常使用这些请求进行文件上传,以及在单个请求中传输多种类型的数据 (例如,文件和 JSON 对象一起传输)。
1 paths: 2 /upload: 3 post: 4 summary: Upload a file 5 description: Upload a file using multipart/form-data encoding 6 operationId: uploadFile 7 tags: 8 - file 9 requestBody: 10 required: true 11 content: 12 multipart/form-data: 13 schema: 14 type: object 15 properties: 16 file: 17 type: string 18 format: binary 19 description: The file to upload 20 description: 21 type: string 22 description: A description of the file (optional) 23 required: 24 - file 25 responses: 26 "200": 27 description: Successful upload 28 content: 29 application/json: 30 schema: 31 type: object 32 properties: 33 message: 34 type: string 35 fileId: 36 type: string
任何使用 multipart/form-data 内容类型定义的请求体都将被视为多部分请求。在给定的多部分请求中,具有 format:binary 的字符串参数将表示任意文件。
如果您的端点支持文件数组,那么您的请求体必须使用数组类型。
1 paths: 2 /upload: 3 post: 4 summary: Upload multiple files 5 operationId: uploadFiles 6 requestBody: 7 content: 8 multipart/form-data: 9 schema: 10 type: object 11 properties: 12 files: 13 type: array 14 items: 15 type: string 16 format: binary 17 description: An array of files to upload