Home All Groups Group Topic Archive Search About


Author
1 Jul 2009 8:43 PM
arganum
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

Author
1 Jul 2009 10:34 PM
Erland Sommarskog
arganum (u52955@uwe) writes:
> 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

If you want to keep track of your path, that sounds like a problem
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
Are all your drivers up to date? click for free checkup

Author
2 Jul 2009 2:37 AM
Michael Coles
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.

--

========
Michael Coles
"Pro T-SQL 2008 Programmer's Guide"
http://www.amazon.com/T-SQL-2008-Programmer-rsquo-Guide/dp/143021001X


Show quoteHide quote
"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
>