QA
Intermediate LevelREST APIs & Web Services

How does Content-Disposition header control file download filenames and inline viewing?

❓ Interview Prompt: Explain `Content-Disposition` header, `inline` vs `attachment`, specifying file download filenames (`filename="report.pdf"`), and security.

The 'Content-Disposition' HTTP response header tells the browser whether to display a file inline or prompt a file download dialog:

Header Variants:

1
'Content-Disposition: inline': Browser displays the file inside the browser window (e.g. viewing PDF or image directly).
2
'Content-Disposition: attachment; filename="Monthly_Report_2026.pdf"': Forces browser to open "Save As" download dialog with the designated filename!

Code Implementation Example

typescript
app.get('/api/v1/reports/pdf', (req, res) => {
  const filePath = './reports/july.pdf';
  res.setHeader('Content-Type', 'application/pdf');
  res.setHeader('Content-Disposition', 'attachment; filename="Monthly_Report_2026.pdf"');
  fs.createReadStream(filePath).pipe(res);
});
💡Setting Content-Disposition attachment header to force PDF file downloads.
🎯 Interview Key Takeaway

Use Content-Disposition: attachment; filename=... to force browser file downloads with custom filenames.

#Content-Disposition#Downloads#HTTP Headers#Intermediate
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?