|
sql
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Saving images
I hope that I can explain what I am trying to do well enough to get help with
it. I made an application where my user will browse for an image on their computer and when they submit the form, the image will be saved in my webserver that I have hosted with someone. What I need to have happen as well is, in SQL, have the path to the image that was just saved on the webserver saved in a table I have created in SQL so that when I query the table, I can display the image. I am not sure how to do this. Ideas or examples would be great Thank you arganum (u52955@uwe) writes:
> I hope that I can explain what I am trying to do well enough to get help If you want to keep track of your path, that sounds like a problem> with it. I made an application where my user will browse for an image on > their computer and when they submit the form, the image will be saved in > my webserver that I have hosted with someone. What I need to have happen > as well is, in SQL, have the path to the image that was just saved on > the webserver saved in a table I have created in SQL so that when I > query the table, I can display the image. I am not sure how to do this. > > Ideas or examples would be great suitable for a forum dedicated to the web software you are using. Or you should contact your web host to see if they permit this at all. However, I don't really like storing only the path in the database. That gives you quite a problem with backups. And this is a hosted solution, you need to be sure that your host backs everything up properly. I would not cound on that. I have a very quick example on my web site that shows how to save an image into database using ADO .Net: http://www.sommarskog.se/blobload.txt -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx Assuming you're talking about a web application all you would need to do is
grab the path from the database and plug it into your <IMG SRC=""> tag. Of course you'll need to make the path relative to the URL, which might require some manipulation on your part. You can also save the image to a varbinary(max) column and retrieve it as Erland recommends. Storing and retrieving the data is easy. Displaying it is the slightly harder part. If you're using ASP.NET you can load the varbinary(max) data into a Byte array and then use a MemoryStream to load an Image. If you're using another platform you'll need to approach the issue differently. You might want to post a question to the .NET newsgroups (and Goog^H^H^H^H -- Bing up) something to the effect "how do I display a graphic stored in a Byte array on a web page", or something to that effect. -- Show quoteHide quote======== Michael Coles "Pro T-SQL 2008 Programmer's Guide" http://www.amazon.com/T-SQL-2008-Programmer-rsquo-Guide/dp/143021001X "arganum" <u52955@uwe> wrote in message news:98706c628122f@uwe... >I hope that I can explain what I am trying to do well enough to get help >with > it. > I made an application where my user will browse for an image on their > computer and when they submit the form, the image will be saved in my > webserver that I have hosted with someone. What I need to have happen as > well > is, in SQL, have the path to the image that was just saved on the > webserver > saved in a table I have created in SQL so that when I query the table, I > can > display the image. I am not sure how to do this. > > Ideas or examples would be great > > Thank you > There are many examples on the web, depending on your platform this can differ. Some here:
http://www.codeguru.com/vb/vb_internet/database/article.php/c7427 http://www.aspnettutorials.com/tutorials/database/Save-Img-ToDB-Csharp.aspx http://www.databasejournal.com/features/mssql/article.php/3724556/Storing-Images-and-BLOB-files-in-SQL-Server-Part-2.htm http://www.databasejournal.com/features/mssql/article.php/3732256/Storing-Images-and-BLOB-files-in-SQL-Server-Part-3.htm http://www.databasejournal.com/features/mssql/article.php/3738276/Storing-Images-and-BLOB-files-in-SQL-Server-Part-4.htm You may want to start by reading the following white paper, which explains storage in DB vs. file system. http://research.microsoft.com/apps/pubs/default.aspx?id=64525 If you use SQL Server 2008 then FILESTREAM is another option.
Other interesting topics
Autostatistic ON/OFF on separate tables?
sql server management studio to connect to database Raid levels Create Database on the server Upgrading from SQL Express to SQL Enterprise Install SQL Server 2008 Questions .... sql replication SQL Server Programming Books Rolling back bcp takes forever. Shouldn't. SQL-server Strange Behaviour ? |
|||||||||||||||||||||||