Almost every web application requires some form of file upload. You may want to allow a user to upload a profile picture or to import any kind of data.
Multiple ways to implement the file upload
Depending on the size of the files and the regularity of the upload you have two options to implement the upload:
Directly upload the file to a data store
The fastest and resource friendliest way is to directly upload the file from the client to a data store. This typically requires the client to have the security credentials for the data store:
But giving security credentials to potential untrusted clients isn’t a realistic approach for most web applications. Instead you want to use a token that provides clients restricted access to a specific resource for a limited validity period. This pattern is known as Valet Key pattern.
Upload the file through a middleware
The second option is to upload the file to your middleware (API) which will handle the movement of the data to the data store.
This approach prevents us from exposing any information about the underlying data store to the client. We could even change our Data Store (e. g. from Azure Blob Storage to Azure File Storage) without updating the client.
The downside is that it absorbs valuable resources from our middleware like compute, memory and bandwidth.