asp.net-coreamazon-s3object-storage

ASP.NET Core Images and other files


We have a few proyects that work together in ASP.NET Core 8: a web mvc app and a web api to serve endpoints to a mobile app.

It is a multi-tenant system where tenants (clients) can store logos, photos, pdf docs and almost all of them can be shown in a public web page or the mobile app, while others are privete to each client.

At the moment, we have all images in the wwwroot of the web app, making some tricks to send the url to the mobile app so it can also show those images.

SOme clients have almost 5Gb of photos and other data.

Database storing is not an option, so we are thinking of having those files in an external storage. We are reading about AMazon S3 buckets or other companies buckets, it doesn't have to be Amazon, but we are worried on how can this affect to performance and costs.

Is it a good practive to have the files in a bucket? How can I show a simple image, such a logo, in a web page when that image is in a bucket? temporary urls? reading the file in my server and posting it?

And what about the costst...imagine 5Gb per client, having more than 200 clients...

Would it be better to have the files in our server but in another disk o even get another server just for files? But how can we avoid people from getting certain private images?

Thanks.


Solution

  • First of all, both hosting files by yourself such as `have the files in our server but in another disk/get another server just for files`, and hosting files with Cloud Service such as AWS/Azure are good options. It depends on your budget and how much effort you would like to pay for the file management system. The differences between host files in your server and in Could are similar to differences between IaaS and PaaS/SaaS, you can ask AI to give you a detailed explanation on it.

    I think budget should be considered first, and I will use Azure as example. In your scenario, files you need to store and load are logos/photos/pdf docs, so that the service is Azure we need to choose is Azure blob storage, it matches your requirement perfectly. And you can use pricing calculator to calculate how much you need to pay for the service. If you prefer to host the files in your own server, then we need to consider whether there's high frequence write/update operations on those files or just loading and display. Just like you know IO-intensive model has high demand on disk while Compute-intensive model has high demand on CPU. You need to ensure your server could match the requirement ahead, and calculator how much you need to pay for the server.

    The next we need to consider is how much effort we need to pay for files management, as you mentioned that `avoid people from getting certain private images`. I think it relays on the authentication and authorization you set in your project. Let's say all your files are served through a controlled endpoint, then we just need to enforce authentication on the endpoint. If we don't want to use this plan, then we will face an issue that when uses signed in and get the image URL, they can then visit the URL directly without signing in net time. In this scenario, it is complex, and it depends on your structure to design the restriction. For example, if you used IIS + windows authentication, then IIS could help you to enforce users to authenticate ahead then to visit files hosts by IIS. But if we use Cloud Service like Azure Blob Storage, then we can also serve the files through controller endpoints too, if we also hope to access files directly but with restriction, we can use Shared Access Signatures (SAS) token or using Azure AD authentication.

    Anyway, there's no best plan but only suitable plan. We also need to adjust the structure following the development of the application. Using Cloud service can reduce your effort and hosting by yourself might reduce the payment.