0

I am developing a project in which I have to use upload file. I am using ASP.NET MVC3(C#) as frontend and SQL Server 2008 R2 as backend. Now for uploading a file I have to options:

1) Uploading a file to specific directory of project and storing its path into the database.(before uploading file to that directory I have to change file name as current timestamp so all files will have unique name.)

2) Uploading file direct into the database.

Which option will be better? My project upload files in KBs(pdf/word/images).

Dhwani
  • 7,484
  • 17
  • 78
  • 139

3 Answers3

3

Storing directly on the file system typically gives better performance. Storing in the DB means you can have the file insert and updating of metadata (which I suppose you'll store in some table in the DB) done within the same transaction.

A third option is to use the file stream features of MSSQL that let you handle the files as fields in the DB, but also access them directly as files through a share.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
  • okie. In which case 2nd option will be beneficial? – Dhwani Apr 27 '13 at 06:54
  • 1
    You get transaction support for the file handling, so you can update meta data and the file together. You will have all your data in one place simplifying backup etc. and you can use one data access layer. – Anders Abel Apr 27 '13 at 06:57
0

I prefer storing the file in ftp server and putting its path in the database. Also, using a timestamp for the file name doesn't seem right. Using the db key value as file name is a slightly better idea.

Ofcourse, there's an additional complexity of maintaining a transaction - the file system and the db should be in sync always.

aquaraga
  • 4,138
  • 23
  • 29
0

Storing a path. You can easier to change your files.