开发者

what is the best way to have a user managed gallery on my asp.net mvc website

i have a website where one 开发者_JAVA百科page is a set of static pictures. users want to be able to upload their own pictures and have it shown instead of the static list. i see code like this which explains a good way to have an upload interface for pictures. i am trying to figure out if i should store the pictures on my web server file system or in my SQL server database or somewhere else.

any suggestions for best practices here?


In the example at the link that you suggest the programmer use a xml file. This solution is god for low band sites and small number of images. But what hapen if two user try to upload a file at the same time? Probably the second user will get an error because the xml files is already in use.

I suggest you to store your pictures in filesystem and the pictures metadata (description, tags, geotag...) in a db.

Avoid to store the binary data in the db. You will get a very inefficient db performances and very big size.


Storing in file system is easier to implement and you can take advantage to use the Directory Structure. However, if you need anything more than simple hirerachy structure(like tagging for instance), most likely you need an database to do the index (can be SQL server or XML Dbs).

Here comes the second problem. If you need indexing, the meta data is stored in DB, how about the actual binary image data? Putting binary in SQL is easy to maintain, but you need to implement custom caching strategy from your web server (dumping the image data to web server local disk drive), to avoid too much traffic between web/db.

On the other hand, you can just keep the key in db, and save the image in local disk (of web server), this is easy to implement, but two problem may arise:

  1. More difficult to scale. Imagine you need more than one web server, syncing content like this might be a problem.

  2. File system indexing. If you store the file in local, chances are all files are stationed in one single folder. For any file system, the more file stored in one location means the slower it can look for or fetching content from it. An image gallery can grows to thousands and millions of files, it may cause the problem. (Of course, you can employ some strategy to separate the storage, but this increase the complexity).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜