I would recommend looking at the WebDAV implementation - they are usually integrated into a web server (for example, Apache) and support most of the standard file system operations that you need.
If you really want to create it yourself, you can also launch an object storage platform, such as OpenStack "Swift", with support for your SAN or NAS device via NFS / iSCSI.
EDIT . You want to save a large number of photos. There are various NoSQL databases that also solve this problem. However, you can also solve the problem using your own network file protocol, such as NFS.
NFS will work well (v4.1 + anyway) in most of your typical file system read and write operations. However, you'll also need a way to index and retrieve photo metadata and provide access control mechanisms, and that is where performance can get complicated.
When the file is uploaded to your HTTP API, you must calculate its MD5 hash content by storing the original file name, owner ID, and other metadata in the relational database. Then write a photo of your NFS mount in a specific βbucketβ.
For example, suppose you have a photo with MD5 content: e240a38624f4a370bd2ec65cf771134b . Assuming your NFS mount is in /srv/content , you should write the photo to the path /srv/content/e240/a38624f4/a370bd2ec65cf771134b.jpg - split the MD5 hash to create prefix folders.
When your user later wants to get the image, he can request it through the data stored in the relational database, your API can find the MD5 hash file and then find it in the file system using a similar operation.
Remember that using MD5 can lead to conflicts if you have so many different files, so you can use a different hash scheme or a combination of two or more to prevent this from happening.
jmkeyes
source share