I am writing an OpenAPI description to upload images and retrieve images.
I am not sure which format and type I should use.
This is what I've tried:
/uploadimage:
post:
tags:
- images
summary: to upload image
requestBody:
content:
application/json:
schema:
type: object
properties:
imageID:
type: integer
example: 103983
image:
type: string
format: byte
There are two ways you can do this.
First and simplest, you can upload files directly using the relevant media type. For example,
The reason this is simple is that it is very easy for the client to make this call:
If you want to send other metadata alongside the request, as it appears you want to do in your question example, you should use a mutlipart form request. For example,
The problem with multipart requests is that it is complex for your clients to make calls. To call the above endpoint looks like this:
So, even though you can pass metadata with your file, it is much simpler and easier to pass just the file.