FileDummy Logo
FileDummy
Kiểm Thử & QA Với Tệp Tin

Kiểm Thử API Upload Tệp Bằng Postman: Multipart, Binary & Tự Động Hóa

Hướng dẫn cấu hình kiểm thử upload file trong Postman. Viết script assertion tự động kiểm tra mã phản hồi và schema cho kỹ sư QA.

14 tháng 9, 20269 phút đọc1,420 lượt xem
postmanapi-testingfile-uploadqamultipart

Testing file upload APIs with Postman is an essential step in verifying backend file ingestion, multipart encoding, validation boundaries, and cloud storage presigned URL endpoints. This guide covers end-to-end setup for automated Postman testing.

Setting Up Multipart/Form-Data Uploads in Postman

When testing standard REST endpoints accepting multipart/form-data, Postman provides native file attachment capabilities.

Step 1: Configure the Request Body

  1. Set the HTTP method to POST and enter your endpoint URL (e.g., https://api.example.com/v1/uploads).
  2. Navigate to the Body tab and select form-data.
  3. In the key column, type the field name your server expects (such as file or attachment).
  4. Hover over the right edge of the key field, click the dropdown, and change the type from Text to File.
  5. Click Select Files and choose a sample test file.
Verified Test Asset.docx

Need a clean 10MB Word document to test your file upload API? Download our verified sample file.

Tải File Mẫu 10MB DOCX →

Automated Postman Tests for File Upload APIs

To verify response status, payload schemas, and uploaded file attributes, use Postman's Tests script tab:

JavaScript
pm.test("Status code is 201 Created", function () {
  pm.response.to.have.status(201);
});

pm.test("Response contains valid file metadata", function () {
  const json = pm.response.json();
  pm.expect(json).to.have.property("fileId");
  pm.expect(json).to.have.property("fileSize");
  pm.expect(json.mimeType).to.eql("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
});

pm.test("Upload processing time is under 2000ms", function () {
  pm.expect(pm.response.responseTime).to.be.below(2000);
});

Testing Binary Raw Uploads (Octet-Stream)

Some high-throughput APIs accept binary streams directly without multipart overhead:

  1. Under Body, select binary.
  2. Select your test binary file.
  3. In the Headers tab, explicitly set Content-Type to application/octet-stream or the appropriate MIME type.

Testing File Size Limits and Error Responses

Be sure to create negative test cases in your Postman collection:

  • Empty file (0 bytes): Verify your server returns HTTP 400 Bad Request with a clear message.
  • Oversized file (e.g. 50MB against a 20MB limit): Verify HTTP 413 Payload Too Large.
  • Wrong MIME type: Ensure your backend rejects disallowed formats with HTTP 415 Unsupported Media Type.
NDL

Nguyễn Đại Long

Tác Giả

Backend Lead • Chuyên gia Kiến trúc Hệ thống Phân tán & Lưu trữ Đám mây

Hơn 4 năm kinh nghiệm thiết kế các hệ thống xử lý tệp tải lên thông lượng lớn, tối ưu hóa cơ sở dữ liệu và hạ tầng phân tán Cloudflare R2 / AWS S3. Người sáng lập FileDummy và Mạng lưới Hệ sinh thái NDL.

Bài viết này có hữu ích không?

Bấm Thích để ủng hộ tác giả và giúp bài viết lan tỏa tới cộng đồng lập trình viên.

Thảo Luận Kỹ Thuật & Đóng Góp Ý Kiến (0)

Chia sẻ kết quả benchmark, phản hồi các trường hợp biên hoặc đặt câu hỏi chuyên môn.

0/3000

Chưa có bình luận nào. Hãy là lập trình viên đầu tiên bắt đầu cuộc thảo luận!

Câu Hỏi Thường Gặp (FAQ)

How do I upload a file in Postman using multipart/form-data?

In the request Body tab, select form-data, add a key with type File, then select your local file. Postman automatically sets the Content-Type: multipart/form-data header with the correct boundary — do not set it manually.

How do I upload a file as raw binary in Postman?

Select Body → binary, then choose your file. This sends the file as the raw request body without form encoding — useful for APIs expecting Content-Type: application/pdf directly in the body, or for direct S3 PUT uploads.

Why does Postman fail with large files?

Postman Desktop has no inherent size limit. Issues usually come from the API server: nginx body size limit, Express bodyParser limit, or AWS API Gateway's 10MB hard limit. Check server logs for 413 Request Entity Too Large errors.

Bài Viết Liên Quan