Uploading data
Learn how to upload data to an API using Hoppscotch.
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 formatmultipart/form-data
: for uploading encoded filesapplication/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:
- Select the
POST
HTTP method and set your API Endpoint URL. - Add the necessary headers.
- To add your image file click in the body tab and select
multipart/form-data
in the content-type dropdown. - Give your file a name and click on
choose files
to select your file. - 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:
- Go to the Body tab and select
multipart/form-data
from the Content Type dropdown. - Add the required data for your request by uploading files or entering values.
- 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 orapplication/json
for JSON data). - 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:
- Select the POST or PUT HTTP method and set your API Endpoint URL.
- In the Body tab, select
application/octet-stream
from the Content Type dropdown. - Upload your binary data by selecting the file from your local machine.
- Click Send to upload the binary data.
Was this page helpful?