APIs can also be used to upload encoded content to a server. This is usually done with PUT or POST methods.

The most common content types are:

  • application/json: for content in JSON format
  • multipart/form-data: for uploading encoded files
  • application/octet-stream: for uploading binary data directly

Uploading a file

To upload a file, the data you send in a POST request must be of the content types application/x-www-form-encoded and multipart/form-data.

Uploading an image

Let’s take a look at uploading an image file to an API using Hoppscotch:

  1. Select the POST HTTP method and set your API Endpoint URL.
  2. Add the necessary headers.
  3. To add your image file click in the body tab and select multipart/form-data in the content-type dropdown.
  4. Give your file a name and click on choose files to select your file.
  5. Click “Send” to upload your file.

Set Content Type for Specific Parameters in multipart/form-data

When sending multiple types of data in a single request using multipart/form-data, you can assign a specific content type to each parameter in Hoppscotch. Here’s how:

  1. Go to the Body tab and select multipart/form-data from the Content Type dropdown.
  2. Add the required data for your request by uploading files or entering values.
  3. To specify content types for parameters, enable the “Show Content Type” option. Then, choose the appropriate content type for each parameter (e.g., text/plain for plain text, image/png for a PNG image or application/json for JSON data).
  4. Click Send to submit the multipart data, with each parameter using its specified content type.

Uploading Binary Data

When uploading binary files, you may want to send raw binary data instead of files in a multipart form. This is typically done using the application/octet-stream content type. Follow these steps to upload binary data:

  1. Select the POST or PUT HTTP method and set your API Endpoint URL.
  2. In the Body tab, select application/octet-stream from the Content Type dropdown.
  3. Upload your binary data by selecting the file from your local machine.
  4. Click Send to upload the binary data.
Currently, the Hoppscotch Desktop App does NOT support uploading Binary files directly as request bodies for APIs.