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:
- Start by opening the Postman application.
- Click on the "New" button in the top left corner of the application.
- Select the "Request" option.
- In the request window, select the appropriate HTTP method (e.g. POST, PUT, etc.) from the dropdown list.
- Enter the URL of the endpoint that you want to send the request to in the "Enter request URL" field.
- In the "Body" tab, select the "form-data" option. (Postman automatically sets the
Content-Typeheader tomultipart/form-datawhen this option is selected.) - Add a new form field by clicking on the "Add a key" button.
- In the "Key" field, enter the name of the field that you want to send.
- 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.
- Add another form field by clicking on the "Add a key" button again.
- In the "Key" field, enter the name of the JSON data field that you want to send.
- 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.
- 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.