Upload endpoints need real files to test properly: the exact size matters for limits, the real content matters for type detection, and large files reveal timeouts. This guide shows how to use files generated with FileMock in the most common API tools.
Step 1: Prepare the Test Files
Generate the valid files in FileMock and save them in one folder in your project, for example tests/fixtures/upload/:
| File | FileMock settings | Purpose |
|---|---|---|
valid-image-100kb.jpg | Image, JPG, 0.1 MB | Happy path |
valid-doc-1mb.pdf | Document, PDF, 1 MB | Standard document |
valid-video-5mb.mp4 | Video, MP4, 5 MB | Larger upload |
oversized-20mb.jpg | Image, JPG, 20 MB | Size limit (for a 10 MB limit) |
unsupported.rtf | Document, RTF, 0.1 MB | Format not on the allowlist |
Then derive the edge cases with a few commands. FileMock only creates valid files, so these are made from the files above:
cd tests/fixtures/upload
: > empty.txt # empty file
cp valid-doc-1mb.pdf wrong-content.jpg # PDF content, .jpg name
head -c 2048 valid-image-100kb.jpg > truncated.jpg # unreadable image
FileMock sizes are binary megabytes (1 MB = 1,048,576 bytes). If your API defines limits in decimal megabytes, check byte counts with
wc -c < file.
Postman
Sending a File
- Create a
POSTrequest to your upload URL, for example{{baseUrl}}/api/upload. - Open Body → form-data.
- Add a key named
file(or whatever your API expects), change its type from Text to File, and select a file fromtests/fixtures/upload/. - Add other form fields as Text keys if your API needs them.
Postman sets the multipart/form-data header and boundary automatically. Don't add a Content-Type header yourself.
Test Scripts
Add assertions in the request's Tests (or Post-response) tab:
// Valid upload
pm.test("Upload succeeds", function () {
pm.response.to.have.status(200);
const body = pm.response.json();
pm.expect(body.size).to.be.above(100000);
pm.expect(body.type).to.eql("image/jpeg");
});
pm.test("Response time is acceptable", function () {
pm.expect(pm.response.responseTime).to.be.below(5000);
});
For the oversized file, duplicate the request, select oversized-20mb.jpg and assert the rejection instead:
pm.test("Oversized file is rejected", function () {
pm.response.to.have.status(413);
pm.expect(pm.response.json().error).to.match(/too large/i);
});
Create one request per test file in a collection folder (valid, limits, formats, edge-cases) so the collection doubles as documentation.
Running the Collection with Newman
Newman resolves file paths relative to its working directory. Point it at the fixtures folder:
npx newman run upload-tests.postman_collection.json \
--environment staging.postman_environment.json \
--working-dir tests/fixtures/upload \
--reporters cli,json \
--reporter-json-export newman-results.json
In the collection, reference files by name only (valid-doc-1mb.pdf) so the same collection works on every machine.
Insomnia
- Create a
POSTrequest and set the body type to Multipart Form. - Add a field named
file, switch its type to File, and choose a file from the fixtures folder. - Use an environment variable such as
{{ _.base_url }}for the URL so the same requests work for local and staging.
VS Code REST Client
The REST Client extension reads a file into a multipart body with < followed by a path relative to the .http file:
@baseUrl = https://staging.example.com
### Valid image upload
POST {{baseUrl}}/api/upload
Content-Type: multipart/form-data; boundary=FileMockBoundary
--FileMockBoundary
Content-Disposition: form-data; name="file"; filename="valid-image-100kb.jpg"
Content-Type: image/jpeg
< ./fixtures/upload/valid-image-100kb.jpg
--FileMockBoundary--
### PDF content declared as an image (should be rejected)
POST {{baseUrl}}/api/upload
Content-Type: multipart/form-data; boundary=FileMockBoundary
--FileMockBoundary
Content-Disposition: form-data; name="file"; filename="wrong-content.jpg"
Content-Type: image/jpeg
< ./fixtures/upload/wrong-content.jpg
--FileMockBoundary--
cURL
cURL is the quickest way to script the whole set. -F "file=@path" sends a multipart upload, and ;type= overrides the declared content type:
#!/usr/bin/env bash
BASE_URL="https://staging.example.com"
DIR="tests/fixtures/upload"
upload() {
local file=$1 type=$2
local status
status=$(curl -s -o /dev/null -w "%{http_code}" \
-F "file=@${DIR}/${file};type=${type}" "${BASE_URL}/api/upload")
echo "${file} (${type}) -> ${status}"
}
upload valid-image-100kb.jpg image/jpeg # expect 200
upload valid-doc-1mb.pdf application/pdf # expect 200
upload oversized-20mb.jpg image/jpeg # expect 413
upload unsupported.rtf application/rtf # expect 400 or 415
upload empty.txt text/plain # expect 400
upload wrong-content.jpg image/jpeg # expect 400 or 415
upload truncated.jpg image/jpeg # expect 400 or 422
Simple Concurrency Check
for i in $(seq 1 10); do
curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" \
-F "file=@${DIR}/valid-doc-1mb.pdf" "${BASE_URL}/api/upload" &
done
wait
For real load testing, use a dedicated tool such as k6 or JMeter with the same fixture files.
Running in CI
FileMock runs in the browser, so there's no command to call from a CI job. Generate the files once, then either commit the small ones to the repository or store the large ones in your artifact storage and download them in the job:
name: Upload API tests
on: [push, pull_request]
jobs:
upload-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Small fixtures are committed in tests/fixtures/upload.
# Large ones could be downloaded from your artifact storage here.
- name: Run upload tests
run: |
npx newman run upload-tests.postman_collection.json \
--environment ci.postman_environment.json \
--working-dir tests/fixtures/upload \
--reporters cli,json \
--reporter-json-export newman-results.json
- uses: actions/upload-artifact@v4
if: always()
with:
name: newman-results
path: newman-results.json
Expected Results Cheat Sheet
| File | Expected response |
|---|---|
valid-image-100kb.jpg | 200/201, correct size and type returned |
valid-doc-1mb.pdf | 200/201 |
oversized-20mb.jpg | 413, request stopped early |
unsupported.rtf | 400 or 415 with the list of allowed types |
empty.txt | 400 with a clear message |
wrong-content.jpg | 400 or 415, detected from content |
truncated.jpg | 400 or 422, never a 500 |
A 500 for any of these files usually means the server tried to process a file it should have rejected earlier.
Generate the files for these tests with FileMock: the PDF generator, the video generator or all file generators. They're created in your browser and never uploaded to a server.
