W3docs

How to upload a file and JSON data in Postman?

To upload a file and JSON data in Postman, you can follow these steps:

To upload a file and JSON data in Postman, you can follow these steps:

  1. Start by opening the Postman application.
  2. Click on the "New" button in the top left corner of the application.
  3. Select the "Request" option.
  4. In the request window, select the appropriate HTTP method (e.g. POST, PUT, etc.) from the dropdown list.
  5. Enter the URL of the endpoint that you want to send the request to in the "Enter request URL" field.
  6. In the "Body" tab, select the "form-data" option. (Postman automatically sets the Content-Type header to multipart/form-data when this option is selected.)
  7. Add a new form field by clicking on the "Add a key" button.
  8. In the "Key" field, enter the name of the field that you want to send.
  9. In the "Value" field, click the dropdown menu next to the input box, select the "File" option, and choose the file that you want to upload.
  10. Add another form field by clicking on the "Add a key" button again.
  11. In the "Key" field, enter the name of the JSON data field that you want to send.
  12. In the "Value" field, enter the JSON data as a string value. Ensure any internal quotes are properly escaped if the JSON contains nested structures.
  13. Click the "Send" button to send the request.

That's it! You should now be able to upload a file and JSON data in Postman.

Equivalent cURL command:

curl -X POST 'https://example.com/api/upload' \
  -F 'file=@/path/to/file.pdf' \
  -F 'jsonData={"key":"value"}'

Note: For nested JSON, pass the entire object as a single string value. To upload multiple files, add additional form fields with the same key name or use array notation (e.g., files[]) depending on your server's requirements.