swagger和openAPI: 上传文件

摘要:
格式:content:schema:properties:pilename:type:text/plain[filecontentgothere]------WebKitFormBoundaryWfPNVh4wuWBlyEyQContent Disposition:swagger和openAPI:https:
[

上传文件

在OpenAPI 3.0中,您可以描述直接使用请求内容上传的文件和使用multipart请求上传的文件。

使用requestBody关键字来描述包含文件的请求负载。在下content,指定请求媒体类型(如image/pngapplication/octet-stream)。文件使用or 的type: string模式,具体取决于文件内容的编码方式。format: binaryformat: base64

例如:

requestBody:
  content:
    image/png:
      schema:
        type: string
        format: binary

该定义对应于如下所示的HTTP请求:

POST /upload
Host: example.com
Content-Length: 808
Content-Type: image/png

[file content goes there]

通过多部分请求上传

要描述与其他数据一起发送的文件,请使用multipart媒体类型。例如:

      requestBody:
        content:
          multipart/form-data:
            schema:
              properties:
                orderId:
                  type: integer
                userId:
                  type: integer
                fileName:
                  type: string
                  format: binary

相应的HTTP请求有效载荷将包含多个部分:

POST /upload
Host: example.com
Content-Length: 2740
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryWfPNVh4wuWBlyEyQ

------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="orderId"

1195
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="userId"

545
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileName"; filename="attachment.txt"
Content-Type: text/plain

[file content goes there]
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ

多文件上传

使用multipart媒体类型定义上传任意数量的文件(一组文件):

      requestBody:
        content:
          multipart/form-data:
            schema:
              properties:
                filename:
                  type: array
                  items:
                    type: string
                    format: binary

相应的HTTP请求如下所示:

POST /upload
Host: example.com
Content-Length: 2740
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryWfPNVh4wuWBlyEyQ

------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileName"; filename="file1.txt"
Content-Type: text/plain

[file content goes there]
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileName"; filename="file2.png"
Content-Type: image/png

[file content goes there]

------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileName"; filename="file3.jpg"
Content-Type: image/jpeg

[file content goes there]

------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
]
转载请保留页面地址:https://www.breakyizhan.com/swagger/2965.html

免责声明:文章转载自《swagger和openAPI: 上传文件》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇daocke镜像批量导出脚本用Python获取本机网卡IP数据包下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

微信默认表情符号的代码对照表

之前有不少朋友问我,微信公众平台如何发带有表情符号的图片,其实只需要在信息里面插入表情代码就可以使用的。 微信表情对照表如下: 表情图片 字符串代码 替换关键字 /::) 微笑 /::~ 伤心 /::B 美女 /::| 发呆 /:8-) 墨镜 /::< 哭 /::$ 羞 /::X 哑 /::...

python setup.py 构建

摘要:这篇文章描述了自己动手把需要的代码封装成python模块的方法。完成后,我们可以直接使用pip install xxx下载自己的模块并使用内置的函数。 介绍python作为一门鼎鼎大名的语言,最有优势的地方就是它拥有无数第三方的模块可以直接拿来使用。以numpy(一个用于实现科学计算的模块)为例,常见的用法一般是这样,相信写过python的肯定是见得...

SpringBoot文件分片上传

背景 最近好几个项目在运行过程中客户都提出文件上传大小的限制能否设置的大一些,用户经常需要上传好几个G的资料文件,如图纸,视频等,并且需要在上传大文件过程中进行优化实时展现进度条,进行技术评估后针对框架文件上传进行扩展升级,扩展接口支持大文件分片上传处理,减少服务器瞬时的内存压力,同一个文件上传失败后可以从成功上传分片位置进行断点续传,文件上传成功后再次上...

git提交时忽略了dll

问题说明 突然出现torisegit会自动忽略*.dll文件不会提交,比如:CSharp.dll。 ​ 问题原因 原因是由于安装了Sourcetree,受到了其环境变量的影响。 ​ Windows系统解决方法 解决方法如下: 打开 Sourcetree -> 工具 ->选项->Git,找到全局忽略列表,点击右侧编辑文件,找到*.dll,删...

如何用javac 和java 编译运行整个Java工程

转自:http://blog.csdn.net/huagong_adu/article/details/6929817         前言:本文教你怎么用javac和java命令,以及如何利用脚本(shell或bat)方便处理,并用简单的实例展示这些用法。         IDE是把双刃剑,它可以什么都帮你做了,你只要敲几行代码,点几下鼠标,程序就跑起来...

shell脚本(一)

                                                                                                          shell脚本 定义:脚本就是一条条命令的堆积。常见脚本有:js asp,jsp,php,python Shell特点:简单易用高效Shell分类...