How would you implement direct-to-cloud-storage uploads (bypassing your API server entirely) using pre-signed URLs, and why is this approach preferred for very large files?
Short answer
Rather than routing large file bytes through your API server (consuming its bandwidth, memory, and compute resources), your API generates a time-limited, pre-signed upload URL (via the cloud storage provider's SDK, like Azure Blob Storage's SAS tokens or AWS S3's presigned URLs)…
Advertisement
AModel answer
Rather than routing large file bytes through your API server (consuming its bandwidth, memory, and compute resources), your API generates a time-limited, pre-signed upload URL (via the cloud storage provider's SDK, like Azure Blob Storage's SAS tokens or AWS S3's presigned URLs) that the client uploads directly to, with your API only handling the lightweight metadata coordination -- dramatically reducing server load and improving upload performance for large files.
[HttpPost("request-upload-url")]
public IActionResult RequestUploadUrl(string fileName) {
var blobClient = _containerClient.GetBlobClient(fileName);
var sasUri = blobClient.GenerateSasUri(BlobSasPermissions.Write, DateTimeOffset.UtcNow.AddMinutes(15));
return Ok(new { uploadUrl = sasUri.ToString() });
}
// Client then uploads the actual file bytes DIRECTLY to sasUri, bypassing the API server entirelyReal-world example
A video platform handling multi-gigabyte uploads generates a short-lived pre-signed Azure Blob SAS URL for each upload request, letting clients upload directly to blob storage and completely avoiding routing massive file bytes through the API server's own bandwidth and compute.
Likely follow-ups
- How do you validate the uploaded file's properties (size, type) after a direct-to-storage upload, since your API never saw the actual bytes?
- What are the security considerations for pre-signed URL expiration and scope?
Related topics