Answer
File Upload in Postman
Postman supports file uploads using the form-data body type, which sends files as multipart/form-data.
Step-by-Step File Upload
- ✓Set method to POST (or PUT)
- ✓Enter the upload URL:
https://api.example.com/upload - ✓Click the Body tab
- ✓Select form-data radio button
- ✓Add a key field:
- ✓Type:
file(name of the file parameter the API expects) - ✓Hover over the key field → dropdown appears
- ✓Change type from Text to File
- ✓Type:
- ✓Click "Select Files" in the Value column
- ✓Browse and select your file (PDF, image, CSV, etc.)
- ✓Click Send
Multiple Files
CODE
KEY TYPE VALUE
files File [Select document1.pdf]
files File [Select document2.pdf]
description Text "Batch upload test"
File Upload with Additional Fields
CODE
KEY TYPE VALUE
file File [Select profile.jpg]
user_id Text 12345
title Text "Profile Picture"
is_public Text true
Checking Upload Worked
JavaScript
// In Tests tab — validate upload response
pm.test("File uploaded successfully", function () {
pm.response.to.have.status(200);
const json = pm.response.json();
pm.expect(json.file_id).to.be.a('string');
pm.expect(json.url).to.match(/^https/);
pm.expect(json.size).to.be.above(0);
});
pm.test("Filename is correct", function () {
const json = pm.response.json();
pm.expect(json.filename).to.include("profile");
});
Using Variables for File Paths
In Postman Desktop, you can use the pm.iterationData to pass file paths in Collection Runner:
JavaScript
// Pre-request Script
const filePath = pm.iterationData.get("file_path");
// Note: Postman doesn't support dynamic file paths via variables
// File selection must be done manually in form-data
Common Errors
| Error | Cause | Fix |
|---|---|---|
| 400 Bad Request | Wrong field name | Match API's expected parameter name |
| 413 Payload Too Large | File too big | Check API's max file size |
| 415 Unsupported Media Type | Wrong content type | Use form-data, not raw |
| File not attached | Type is Text not File | Change key type to File |
Testing Upload Limits
Test with:
- ✓✅ Valid file types (PDF, JPG, PNG, CSV)
- ✓✅ File at size limit (e.g., exactly 5MB)
- ✓❌ Oversized file (e.g., 6MB when limit is 5MB) → expect 413
- ✓❌ Invalid file type (e.g., .exe when only images allowed) → expect 400
