2

I am new to MVC and pretty new to web sites development. I have a dilemma how to manage uploaded images.

I have a data layer that uses entity framework in order to store data. In my controller constructor I give the IItemRepository and an IFileRepository implementations.

 public ItemsController(IItemManager itemRepository, IFilesRepository fileRepository)

Mow I store the files in db (filename, mime type, relative server path) and the actual file is stored on the disk. In the controller I do the sync between the database and the folder. Is that the right approach? It seems to me that it is not. I am thinking of moving the IFileRepository into the IItemManager implementation.

Another problem is that for every controller that require files I have to implement the same sync between db and folder structure.

What do you think of storing files in the db?

How did you solved this problem?

Radu D
  • 3,505
  • 9
  • 42
  • 69

2 Answers2

0

See this SO post about saving images. The same cases are applicable in case of other files too.

Community
  • 1
  • 1
Prasanth
  • 3,029
  • 31
  • 44
0

In the controller I do the sync between the database and the folder. Is that the right approach?

No.

I would start by moving most logic (including this synch) to a model so that (1) your controller does not do a whole lot and (2) you can share this logic with other controllers.

Hector Correa
  • 26,290
  • 8
  • 57
  • 73