Mohammad Olfatmiri
Mohammad Olfatmiri

Reputation: 1675

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)) :

~/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 :

  1. are we proceding in a good direction?
  2. should we save files in a root directory or a virtual directory?
  3. imagine our server has 1 TB storage,after storing 1 TB data if we add an extra hard drive how should we manage changes?

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

Upvotes: 4

Views: 1763

Answers (2)

Aydin
Aydin

Reputation: 15294

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...

Upvotes: 1

chui
chui

Reputation: 61

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.

Upvotes: 0

Related Questions