Introduction
file-storage-api is a RESTful API that will interface with your APIs to your File Storage.
Refer to the diagram below:

In the above illustration, the file-storage-api can serve as a central storage for the microservices.
Tech used:
The file-storage-api uses the ff. storage:
MariaDB- for File ID lookupData Storage- currently using local storage, for storing the files.
Problem Description
If you have an large application with the ff. features:
- A consumer-facing application that saves customer information, including their profile photo. (Who doesn't like a site with profile photo?)
- A client-facing application (in this case, the product seller) that uploads product details, including product pictures.
- An incident-tracking application, where customer can upload files for better root cause analysis.
You may try to write each application APIs their own file saving capabilities, but Separation of Concerns dictates that each application should focus on their designated roles.
Solution
Design your client-specific APIs to only reference a locationPath of the upload file. this locationPath is a fileId returned by the file-storage-api.
{
"customerId": "jdoe",
"custPhoto": "file-id.jpg" // file-id format is [id].[extension]
}
Depending on your use case, you may try the ff. approach:
- via uploading to frontend - this is the faster way, just upload the document, get the
file-idand then submit it to your respective APIs. - using
file-storage-apias your downstream storage - this is for generated files by the API (like reports).
Will there there be a use case where interface other than REST needs to be supported?
Notes to consider:
- This
APIonly acts as a RESTful interface to yourFile Storage. As perSOLID'Open for extension, closed for modification's principle. As for the case of large files (which I hope I will never do), do a separate microservice ecosystem where you can implement a microservice flow for queue-ing the upload of large files. (or by chunking them to pieces).
This is a good research idea especially for that dumb fuck SVI's GenRet