How to store User Uploaded Files using MVC.NET on a IIS webserver?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to store User Uploaded Files using MVC.NET on a IIS webserver?



We are working on a Educational website which allows users(teachers and students) to upload files (.pdf,.docx,.png and ... ). We don't have any experience in this area and wanted to make sure we are doing the right thing to store and index these files. We would like to have an architecture that scales well to high volumes of data.

currently we store the path to our files in database like below (Nvarchar(MAX)) :


Nvarchar(MAX)


~/Files/UserPhotos/2fd7199b-a491-433d-acf9-56ce54b6b14f_168467team-03.png



and we use codes below to save and retrieve files :


//save:
file.SaveAs(Server.MapPath("~/Files/UserPhotos/") + fileName);
//retrieve:
<img alt="" src="@Url.Content(Model.FilePath)">



now our questions are :



we searched a lot but did not find any good tutorial or guidelines for correct architecture.

sorry for my bad English.





You might want to consider some sort of "cloud" storage like Amazon S3 or Azure Blob Storage. These are simple enough to integrate into an MVC app and have the added benefit that if you have multiple instances of your web site hosted on different servers all instances have access to the shared storage.
– darth_phoenixx
Jan 31 '16 at 12:52





As @darth_phoenixx mentioned cloud services like azure and Amazon would be a better, more scalable solution than local storage. And if you recon teachers and students are going to be uploading lots of files (heavy ones) then you can also think about off loading this task to a separate uploading service / queue, which would take the load off your application server.
– Amanvir Mundra
Jan 31 '16 at 14:39





@darth_phoenixx Azure Blob Storage is not accessible in my country ....
– Oli
Jan 31 '16 at 17:53




2 Answers
2



In an ideal world, you would be using cloud storage, such as Azure Blob Storage, if that's not an option then the way I would do it is create a separate web service that specifically deals with uploaded files and file storage.



By creating a separate web service that manages file storage, you will have isolated your concerns, this service can monitor hard drive storage spaces and balance them out as documents are being uploaded, and in future if you add additional servers... you will already have separated your service so it won't be as big of a mess as it would be if you didn't.



You can index everything in a SQL data store as files are being uploaded. Your issues are actually much more complicated than what I've just mentioned though...



The other issues that need attention is the game plan if or when one of the hard drives go kaput! Without a RAID 1 configuration of your hard drives, your availability plummets to NADA.



Queue issue number 2... availability != backups... You need to consider your game plan on how you intend to back the system up, how often, during what time of day, etc... The more data you have, the more difficult this gets...



This is why everyone is moving over to Azure / AWS etc... you just don't have to worry about these sort of things anymore...





Azure Blob Storage is not accessible in my country ....
– Oli
Jan 31 '16 at 17:52





Do you mean there isn't a data center located in your country?
– Aydin Adn
Jan 31 '16 at 17:55





No, i live in Iran , because of sanctions against our country we are not able to use these services :)
– Oli
Jan 31 '16 at 17:57





Ridiculous! I would have thought the recent lifts in sanctions would permit it... I think you should send an email to Azure sales, they may be accepting iran soon you never know...
– Aydin Adn
Jan 31 '16 at 18:02



1.I usually save files in this way:


file.SaveAs(Server.MapPath("/Files/UserPhotos/") + fileName);



2.it is better to save it in a virtual directory,so that you can move your files folder to a new an extra hard disk and change your virtual directory's path in IIS when you have too much files in this folder.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard