Advertisement

File Uploads & Streaming Large Files interview questions and answers

15 File Uploads & Streaming Large Files interview questions for ASP.NET Core roles, each with a model answer, examples and likely follow-ups.

15 questions
Advertisement

15 questions

Q11 Advanced Save

How would you implement virus/malware scanning for uploaded files before they're made available for download by other users?

A common pattern uploads the file to a quarantine/staging location first, triggers an asynchronous scan (via an integrated antivirus engine like ClamAV, or a cloud provider's malware scanning service), and only moves the file to its final, publicly-accessible location once the scan confirms it's clean -- rejecting or quarantining files that fail the scan, ensuring no malicious content is ever served to other users even briefly.
[HttpPost("upload")]
public async Task<IActionResult> Upload(IFormFile file) {
    var quarantinePath = await _storageService.SaveToQuarantineAsync(file);
    await _backgroundTaskQueue.QueueBackgroundWorkItem(async ct => {
        var scanResult = await _virusScanner.ScanAsync(quarantinePath, ct);
        if (scanResult.IsClean) await _storageService.PromoteToPublicAsync(quarantinePath);
        else await _storageService.DeleteAsync(quarantinePath);
    });
    return Accepted(new { status = "processing" });
}
Real-world example
A file-sharing platform quarantines every upload and runs it through ClamAV asynchronously before promoting it to publicly-downloadable storage, ensuring a malicious file uploaded by one user is never served to another user even in the brief window before scanning completes.
Likely follow-ups
  • How do you communicate scan status/results back to the uploading user?
  • What's the performance and UX trade-off of synchronous versus asynchronous scanning?
Background Tasks & Hosted Services Security Headers Antiforgery & CSRF Protection
Q12 Intermediate Save

How do you configure IIS or a reverse proxy like nginx to allow large file uploads, given they may impose their own separate size limits beyond Kestrel's?

When ASP.NET Core is hosted behind IIS or a reverse proxy, the proxy layer itself may enforce its own separate maximum request body size (IIS's maxAllowedContentLength in web.config, nginx's client_max_body_size directive) independent of Kestrel's own limit -- all layers in the request path (proxy, Kestrel, and any explicit [RequestSizeLimit] attributes) must be configured consistently, since the most restrictive limit in the chain determines the effective maximum.
<!-- web.config for IIS -->
<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="104857600" />  <!-- 100MB -->
  </requestFiltering>
</security>

# nginx.conf
client_max_body_size 100M;
Real-world example
A team spends hours debugging why uploads larger than 30MB fail despite setting a generous 500MB Kestrel limit, eventually discovering nginx's default client_max_body_size of 1MB in front of their app was the actual restrictive bottleneck.
Likely follow-ups
  • What's the full chain of size limits a large upload must pass through in a typical production deployment?
  • How would you diagnose which specific layer is rejecting an oversized upload?
Hosting Models: Kestrel IIS & Reverse Proxies Diagnostics & Performance
Q13 Advanced Save

How would you implement upload progress reporting to a client during a large file upload, given HTTP doesn't natively provide this?

Since standard HTTP request/response doesn't provide built-in server-to-client progress feedback during an upload in progress, common approaches include: client-side progress via the browser's XMLHttpRequest upload.onprogress event (tracking bytes sent, entirely client-side and not requiring server cooperation), or a separate real-time channel (SignalR) where the server periodically reports bytes-received-so-far as it processes a streamed upload, letting the client display server-confirmed progress rather than just client-side send progress.
// Client-side (XHR upload progress, doesn't need server cooperation)
const xhr = new XMLHttpRequest();
xhr.upload.onprogress = (event) => {
    const percent = (event.loaded / event.total) * 100;
    updateProgressBar(percent);
};
xhr.open('POST', '/api/upload');
xhr.send(formData);
Real-world example
A large file upload UI shows a progress bar driven entirely by the browser's XHR upload.onprogress event, giving users immediate visual feedback without requiring any special server-side progress-reporting infrastructure.
Likely follow-ups
  • How would server-confirmed progress differ from client-side send progress, and when does that distinction matter?
  • How would you implement server-side progress reporting via SignalR for a streamed upload?
SignalR & Real-Time Communication Diagnostics & Performance
Q14 Intermediate Save

What is the difference between temporary file storage (during processing) and permanent storage for uploaded files, and why should uploads generally not be saved directly to their final destination?

Uploads should typically be written to a temporary location first, then validated (file type, virus scan, size checks) and only moved to permanent storage (or a public-facing location) once validation passes -- writing directly to the final destination risks exposing a partially-uploaded, unvalidated, or malicious file to other parts of the system or other users during the brief window before validation completes.
public async Task<IActionResult> Upload(IFormFile file) {
    var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
    using (var stream = File.Create(tempPath)) {
        await file.CopyToAsync(stream);
    }
    if (!await ValidateFileAsync(tempPath)) {
        File.Delete(tempPath);
        return BadRequest("Invalid file");
    }
    await _storageService.MoveToPermStorageAsync(tempPath);
    return Ok();
}
Real-world example
An upload pipeline writes every file to a temporary location first, running size and content-type validation before ever moving it to the permanent, publicly-accessible storage location, preventing an invalid or malicious file from being briefly exposed.
Likely follow-ups
  • How do you ensure temporary files are cleaned up if validation or the upload process crashes midway?
  • What's the security risk of writing directly to a web-accessible directory during upload?
Security Headers Antiforgery & CSRF Protection Background Tasks & Hosted Services
Q15 Beginner Save

What HTTP status code and response should be returned when an upload fails validation (wrong type, too large, missing file)?

Return a 400 Bad Request with a clear, structured error message (ideally following the ProblemDetails format) explaining specifically what validation failed -- wrong content type, size exceeded, or no file provided -- so the client can present an actionable, specific message to the end user rather than a generic failure.
[HttpPost("upload")]
public async Task<IActionResult> Upload(IFormFile? file) {
    if (file is null || file.Length == 0)
        return BadRequest(new ProblemDetails { Title = "No file provided", Status = 400 });
    if (file.Length > MaxSize)
        return BadRequest(new ProblemDetails { Title = "File exceeds maximum size of 10MB", Status = 400 });
    if (!AllowedTypes.Contains(file.ContentType))
        return BadRequest(new ProblemDetails { Title = $"Content type {file.ContentType} not allowed", Status = 400 });
    await _storageService.SaveAsync(file.FileName, file.OpenReadStream());
    return Ok();
}
Real-world example
An image upload endpoint returns a structured ProblemDetails response specifying exactly which validation rule failed (file too large vs wrong type vs missing entirely), letting the client UI show a precise, helpful error message instead of a generic 'upload failed' banner.
Likely follow-ups
  • How does this integrate with the global IExceptionHandler for consistent error formatting?
  • Should validation errors be logged, and at what severity?
Error Handling Model Binding & Validation

Showing 11–15 of 15