I just went through this and decided not to store them to sql server.
Instead I stored the file paths to sql server, and used them to reference the image by ID in a relationship on a seperate table when needed in the file system.
File systems are for files, databases are for data. After research, this is the best way to go about it. As your site grows, it's also cheaper to add hd space than increase SQL DB size.
I am using SQL Server 2008 R2. I wonder should I need to use FILESTREAM? If so how to design the table? I mean do I need to add any other column rather than varbinary column?
Best Regards.
Edit 1: Can I store those images in filesystem compressed?
Keep your friends close and your enemies even closer
The size and use of the data determines whether you should use database storage or file system storage. If the following conditions are true, you should consider using FILESTREAM:
Objects that are being stored are, on average, larger than 1 MB.
Fast read access is important.
You are developing applications that use a middle tier for application logic.
cenk1536
If so how to design the table? I mean do I need to add any other column rather than varbinary column?
Thanks for your reply. If I want to store those images (lets assume they are bigger than 1 Mb), can I somehow compress it and then store? Then when I want to display it on my web app, can I decompress and display it?
Best Regards.
Keep your friends close and your enemies even closer
cenk1536
Contributor
2501 Points
2107 Posts
Store pdf, jpeg, png, doc in Database?
Dec 07, 2012 10:26 AM|LINK
Hi,
I have a web form and user want to attach one of those (pdf, jpeg, png, doc, docx) and store it in SQL Server. Is there a way to do it?
Best Regards.
geniusvishal
Star
13984 Points
2783 Posts
Re: Store pdf, jpeg, png, doc in Database?
Dec 07, 2012 10:31 AM|LINK
Refer:
http://weblogs.asp.net/rajbk/archive/2010/02/20/uploading-and-storing-files-in-sql-using-asp-net.aspx
My Website
www.dotnetvishal.com
Ruchira
All-Star
42885 Points
7019 Posts
MVP
Re: Store pdf, jpeg, png, doc in Database?
Dec 08, 2012 03:11 PM|LINK
Hello,
Yes. You can store them in a varbinary field. Check the below links on how to store and retrieve the files in varbinary field.
http://stackoverflow.com/questions/2579373/saving-any-file-to-in-the-database-just-convert-it-to-a-byte-array
http://weblogs.sqlteam.com/randyp/archive/2008/11/20/60771.aspx
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.poweraddict
Member
12 Points
51 Posts
Re: Store pdf, jpeg, png, doc in Database?
Dec 08, 2012 03:30 PM|LINK
I just went through this and decided not to store them to sql server.
Instead I stored the file paths to sql server, and used them to reference the image by ID in a relationship on a seperate table when needed in the file system.
File systems are for files, databases are for data. After research, this is the best way to go about it. As your site grows, it's also cheaper to add hd space than increase SQL DB size.
cenk1536
Contributor
2501 Points
2107 Posts
Re: Store pdf, jpeg, png, doc in Database?
Dec 12, 2012 08:05 AM|LINK
Hi,
I am using SQL Server 2008 R2. I wonder should I need to use FILESTREAM? If so how to design the table? I mean do I need to add any other column rather than varbinary column?
Best Regards.
Edit 1: Can I store those images in filesystem compressed?
Catherine Sh...
All-Star
23373 Points
2490 Posts
Microsoft
Re: Store pdf, jpeg, png, doc in Database?
Dec 13, 2012 07:17 AM|LINK
Hi,
It depends on your reqirement.
The size and use of the data determines whether you should use database storage or file system storage. If the following conditions are true, you should consider using FILESTREAM:
For this issue, you can follow the links below:
http://msdn.microsoft.com/en-us/library/cc645585(v=sql.105).aspx
http://msdn.microsoft.com/en-us/library/cc645583(v=sql.105).aspx
I am confused your purpose. Do you want to compress the image?
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
cenk1536
Contributor
2501 Points
2107 Posts
Re: Store pdf, jpeg, png, doc in Database?
Dec 13, 2012 09:12 AM|LINK
Hi Catherine Shan,
Thanks for your reply. If I want to store those images (lets assume they are bigger than 1 Mb), can I somehow compress it and then store? Then when I want to display it on my web app, can I decompress and display it?
Best Regards.
Catherine Sh...
All-Star
23373 Points
2490 Posts
Microsoft
Re: Store pdf, jpeg, png, doc in Database?
Dec 13, 2012 09:35 AM|LINK
Hi,
If you want to compress and decompress, you can try to do it using two methods below:
1. Huffman Algorithm. Refer to: http://www.codeproject.com/Articles/19176/How-to-compress-and-decompress-a-file-using-Huffma
2. GZipStream. Refer to: http://justlikeamagic.com/2009/03/27/programmatically-compress-and-decompress-files/
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store