Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I am creating a website that enables underground and local artist to share music beats I've read through a few blogs and its been clearly stated in them that storing data of large sizes in a database is not advised and they say that its better to store in a directory and I've researched around that but I still don't understand the pro's and cons and how its done... I need a safe and secure method/place to store uploaded files because some of the unsigned producers want the option to sell and give away beats for free. I'm not sure if I'm clear enough on my question cause I'm also confused a bit now... What I want the user to be able to do is upload and download media files on my website

Thanks in advance
Posted
Comments
[no name] 18-May-13 11:22am    
Okay so what exactly is your question?
adriancs 18-May-13 11:25am    
He wants to store the uploaded files in folder, but don't want the files to be downloaded directly by other user.
[no name] 18-May-13 11:42am    
Good for you for getting that out of his narrative. However; I am still not seeing any kind of a question or any kind of effort on his part.
mlingo209 18-May-13 11:30am    
Yes adriancs I'm not extensively experience I've done a lot of school projects b4 this is the 1st real world site I'm working on that will actually be hosted so, I get confused easily. I want the best method of storing large media files and being able to downloaded them securely

1 solution

There are a couple of good reasons for not storing the file itself in a database, and they both concern the size of the items concerned.

Until recently, the maximum size of a database file was restricted to a paltry 16GB - it was raised this to 524,272 terabytes which should be enough for anybody (with the possible exception of Google) for a couple of years.

But... that doesn't mean that you should start storing large objects for a web site.
The problem is that you have at least three computers involved here: SQL server which reads the data and transfers it (normally via 1GBit/sec LAN) to the Webserver where your site application is running, which transfers it via a much slower link to your client. This takes up bandwidth (or web server memory) like crazy - start to transfer two large files at the same time and thing start to grind a bit, and the SQL connection (which is a scarce resource) has to be held until the transfer to the web server is complete.

If you are storing the file as a file in a folder on the Webserver, then the data is already local, and SQL does not have to be involved.

The way I do it is to have a DB table which holds four columns: ID, original file name, date inserted, and a link to a guid-based file name in my webserver. The SQL query is nice and quick,(since the info is just two short strings), and the file itself can be transferred from the local harddrive, with the client passed the original name instead of the internal one. The main reason for using Guid based file names is to ensure that two different users don't save the same file and overwrite each other.
 
Share this answer
 
Comments
Mohammed Hameed 18-May-13 16:12pm    
+5 for your solution...
adriancs 18-May-13 23:34pm    
Can the user obtain the real filename on server?
example: www.myweb.com/files/--guid--

One way to protect the files to be direct accessed by user is to put them inside App_Data folder for ASP.NET. Use web respond to transmit the file for user to download.
OriginalGriff 19-May-13 3:45am    
If you are using Membership (and you probably should) then what I do is create a sub directory off the main site root and give it a web.config file that specifies no access at all.
<authorization>
<deny users="*">

Your code can still read the folder and content, but users cannot open any file in the folder, even if they are logged in as admin.

I personally wouldn't keep it in the App-Data folder, because I have data I need to upload with website revision that go in there, and I prefer to allow for a "clean" install if I need it.
Having it as a separate folder also makes it easier for backups - you can put that folder on a different schedule to the rest of the data (it may be that you want one copy, not rolling grandfather-father-son version, particularly for very big files.
adriancs 18-May-13 23:36pm    
+5 for not storing files in database.
This is because it increases the burden when backing up and restoring the database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900