Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > database driven photo gallery with upload

Reply
Thread Tools

database driven photo gallery with upload

 
 
bob garbados
Guest
Posts: n/a
 
      10-29-2004
I am trying to create a database-driven photo gallery for a friend with an
admin form to upload images... I can upload a file to the web server, but I
want to store the image in a database and I want to resize the image before
I save it... How do I take the uploaded .jpg and shrink it to a thumbnail?
How do I pass the uploaded .jpg to a stored procedure that will store the
image as an image datatype in SQL Server 2000? I'm developing this without
Visual Studio.

<%@ Page Language="VB" %>

<script language="VB" runat="server">

Sub Page_Load(Source As Object, E As EventArgs)
End Sub

Sub Button_Click(S as Object, E as EventArgs)

fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho
togallery\NewFile.jpg")
End Sub

</script>
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<form id="frmUpload" method="post" runat="server"
enctype="multipart/form-data">
<input type="file" id="fsoUploadFile" runat="server"><br/>
<asp:button Text="Upload File" OnClick="Button_Click" runat="server"/>
</form>
</body>
</html>


 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      10-29-2004
Here's an article I wrote that describes how to upload images into a
database and get them back out again.
http://steve.orr.net/content/asp200307so_f.asp

Also, here's an image resize routine I wrote:

/*shrink the image proportionately so that neither height nor width is more
than [NewSize] pixels*/

public Image ShrinkImage(Bitmap bmp, int NewSize)

{

double NewWidth;

double NewHeight;

double ShrinkPercent;

System.Drawing.Image.GetThumbnailImageAbort myCallback =

new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);

if (bmp.Width>bmp.Height)

{

NewWidth=NewSize;

ShrinkPercent=(NewWidth/bmp.Width)*100;

NewHeight=(ShrinkPercent/100)*bmp.Height;

}

else

{

NewHeight=NewSize;

ShrinkPercent=(NewHeight/bmp.Height)*100;

NewWidth=(ShrinkPercent/100)*bmp.Width;

}

System.Drawing.Image myShrunkenImage =
bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero);

return myShrunkenImage;

}

public bool ThumbnailCallback(){return false;}


--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



"bob garbados" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am trying to create a database-driven photo gallery for a friend with an
> admin form to upload images... I can upload a file to the web server, but
> I
> want to store the image in a database and I want to resize the image
> before
> I save it... How do I take the uploaded .jpg and shrink it to a thumbnail?
> How do I pass the uploaded .jpg to a stored procedure that will store the
> image as an image datatype in SQL Server 2000? I'm developing this
> without
> Visual Studio.
>
> <%@ Page Language="VB" %>
>
> <script language="VB" runat="server">
>
> Sub Page_Load(Source As Object, E As EventArgs)
> End Sub
>
> Sub Button_Click(S as Object, E as EventArgs)
>
> fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho
> togallery\NewFile.jpg")
> End Sub
>
> </script>
> <html>
> <head>
> <title>Image Upload</title>
> </head>
> <body>
> <form id="frmUpload" method="post" runat="server"
> enctype="multipart/form-data">
> <input type="file" id="fsoUploadFile" runat="server"><br/>
> <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/>
> </form>
> </body>
> </html>
>
>



 
Reply With Quote
 
 
 
 
bob garbados
Guest
Posts: n/a
 
      10-29-2004
Thanks Steve. I actually found your article and used it as a guide to write
my code for uploading the image to the database. I'm working on retreiving
the images now and the resize routine looks great, I'll implement that once
everything else is working.

"Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here's an article I wrote that describes how to upload images into a
> database and get them back out again.
> http://steve.orr.net/content/asp200307so_f.asp
>
> Also, here's an image resize routine I wrote:
>
> /*shrink the image proportionately so that neither height nor width is

more
> than [NewSize] pixels*/
>
> public Image ShrinkImage(Bitmap bmp, int NewSize)
>
> {
>
> double NewWidth;
>
> double NewHeight;
>
> double ShrinkPercent;
>
> System.Drawing.Image.GetThumbnailImageAbort myCallback =
>
> new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
>
> if (bmp.Width>bmp.Height)
>
> {
>
> NewWidth=NewSize;
>
> ShrinkPercent=(NewWidth/bmp.Width)*100;
>
> NewHeight=(ShrinkPercent/100)*bmp.Height;
>
> }
>
> else
>
> {
>
> NewHeight=NewSize;
>
> ShrinkPercent=(NewHeight/bmp.Height)*100;
>
> NewWidth=(ShrinkPercent/100)*bmp.Width;
>
> }
>
> System.Drawing.Image myShrunkenImage =
>

bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero);
>
> return myShrunkenImage;
>
> }
>
> public bool ThumbnailCallback(){return false;}
>
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
>
>
> "bob garbados" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I am trying to create a database-driven photo gallery for a friend with

an
> > admin form to upload images... I can upload a file to the web server,

but
> > I
> > want to store the image in a database and I want to resize the image
> > before
> > I save it... How do I take the uploaded .jpg and shrink it to a

thumbnail?
> > How do I pass the uploaded .jpg to a stored procedure that will store

the
> > image as an image datatype in SQL Server 2000? I'm developing this
> > without
> > Visual Studio.
> >
> > <%@ Page Language="VB" %>
> >
> > <script language="VB" runat="server">
> >
> > Sub Page_Load(Source As Object, E As EventArgs)
> > End Sub
> >
> > Sub Button_Click(S as Object, E as EventArgs)
> >
> >

fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho
> > togallery\NewFile.jpg")
> > End Sub
> >
> > </script>
> > <html>
> > <head>
> > <title>Image Upload</title>
> > </head>
> > <body>
> > <form id="frmUpload" method="post" runat="server"
> > enctype="multipart/form-data">
> > <input type="file" id="fsoUploadFile" runat="server"><br/>
> > <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/>
> > </form>
> > </body>
> > </html>
> >
> >

>
>



 
Reply With Quote
 
bob garbados
Guest
Posts: n/a
 
      10-29-2004
Steve,

I can save the image in the database, but I can't retrieve it. Here's my
code:

Dim con as SqlConnection
Dim strConnectionString as String

strConnectionString = ConfigurationSettings.AppSettings("connection")

con= New SqlConnection(strConnectionString)

Dim dr As System.Data.SqlClient.SqlDataReader
Dim cmdGetPhoto as new SqlCommand("usp_GetPhotos", con)

con.Open()
dr = cmdGetPhoto.ExecuteReader
If dr.Read Then
Response.Write("Photo is here...")
Response.Write("Photo Name: " & dr("PhotoTitle") & "<br/>")
Response.ContentType = dr("PhotoThumbContentType").ToString
Response.OutputStream.Write(CType(dr("PhotoThumb") , Byte()), 0,
CInt(dr("PhotoThumbSize")))
Response.AddHeader("Content-Disposition", dr("PhotoTitle").ToString())
Else
Response.Write("File Not Found.")
End If

'close down the connection
con.Close()

I stepped through the code and it executes the correct lines of code, but
doesn't write anything and the image doesn't show up. What does the
'inherits="CIT.ViewAttachment"' line in your code do?


"Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here's an article I wrote that describes how to upload images into a
> database and get them back out again.
> http://steve.orr.net/content/asp200307so_f.asp
>
> Also, here's an image resize routine I wrote:
>
> /*shrink the image proportionately so that neither height nor width is

more
> than [NewSize] pixels*/
>
> public Image ShrinkImage(Bitmap bmp, int NewSize)
>
> {
>
> double NewWidth;
>
> double NewHeight;
>
> double ShrinkPercent;
>
> System.Drawing.Image.GetThumbnailImageAbort myCallback =
>
> new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
>
> if (bmp.Width>bmp.Height)
>
> {
>
> NewWidth=NewSize;
>
> ShrinkPercent=(NewWidth/bmp.Width)*100;
>
> NewHeight=(ShrinkPercent/100)*bmp.Height;
>
> }
>
> else
>
> {
>
> NewHeight=NewSize;
>
> ShrinkPercent=(NewHeight/bmp.Height)*100;
>
> NewWidth=(ShrinkPercent/100)*bmp.Width;
>
> }
>
> System.Drawing.Image myShrunkenImage =
>

bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero);
>
> return myShrunkenImage;
>
> }
>
> public bool ThumbnailCallback(){return false;}
>
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
>
>
> "bob garbados" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I am trying to create a database-driven photo gallery for a friend with

an
> > admin form to upload images... I can upload a file to the web server,

but
> > I
> > want to store the image in a database and I want to resize the image
> > before
> > I save it... How do I take the uploaded .jpg and shrink it to a

thumbnail?
> > How do I pass the uploaded .jpg to a stored procedure that will store

the
> > image as an image datatype in SQL Server 2000? I'm developing this
> > without
> > Visual Studio.
> >
> > <%@ Page Language="VB" %>
> >
> > <script language="VB" runat="server">
> >
> > Sub Page_Load(Source As Object, E As EventArgs)
> > End Sub
> >
> > Sub Button_Click(S as Object, E as EventArgs)
> >
> >

fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho
> > togallery\NewFile.jpg")
> > End Sub
> >
> > </script>
> > <html>
> > <head>
> > <title>Image Upload</title>
> > </head>
> > <body>
> > <form id="frmUpload" method="post" runat="server"
> > enctype="multipart/form-data">
> > <input type="file" id="fsoUploadFile" runat="server"><br/>
> > <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/>
> > </form>
> > </body>
> > </html>
> >
> >

>
>



 
Reply With Quote
 
bob garbados
Guest
Posts: n/a
 
      10-29-2004
I lied... removed the response.write and everything works beautifully.


"bob garbados" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Steve,
>
> I can save the image in the database, but I can't retrieve it. Here's my
> code:
>
> Dim con as SqlConnection
> Dim strConnectionString as String
>
> strConnectionString = ConfigurationSettings.AppSettings("connection")
>
> con= New SqlConnection(strConnectionString)
>
> Dim dr As System.Data.SqlClient.SqlDataReader
> Dim cmdGetPhoto as new SqlCommand("usp_GetPhotos", con)
>
> con.Open()
> dr = cmdGetPhoto.ExecuteReader
> If dr.Read Then
> Response.Write("Photo is here...")
> Response.Write("Photo Name: " & dr("PhotoTitle") & "<br/>")
> Response.ContentType = dr("PhotoThumbContentType").ToString
> Response.OutputStream.Write(CType(dr("PhotoThumb") , Byte()), 0,
> CInt(dr("PhotoThumbSize")))
> Response.AddHeader("Content-Disposition", dr("PhotoTitle").ToString())
> Else
> Response.Write("File Not Found.")
> End If
>
> 'close down the connection
> con.Close()
>
> I stepped through the code and it executes the correct lines of code, but
> doesn't write anything and the image doesn't show up. What does the
> 'inherits="CIT.ViewAttachment"' line in your code do?
>
>
> "Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Here's an article I wrote that describes how to upload images into a
> > database and get them back out again.
> > http://steve.orr.net/content/asp200307so_f.asp
> >
> > Also, here's an image resize routine I wrote:
> >
> > /*shrink the image proportionately so that neither height nor width is

> more
> > than [NewSize] pixels*/
> >
> > public Image ShrinkImage(Bitmap bmp, int NewSize)
> >
> > {
> >
> > double NewWidth;
> >
> > double NewHeight;
> >
> > double ShrinkPercent;
> >
> > System.Drawing.Image.GetThumbnailImageAbort myCallback =
> >
> > new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
> >
> > if (bmp.Width>bmp.Height)
> >
> > {
> >
> > NewWidth=NewSize;
> >
> > ShrinkPercent=(NewWidth/bmp.Width)*100;
> >
> > NewHeight=(ShrinkPercent/100)*bmp.Height;
> >
> > }
> >
> > else
> >
> > {
> >
> > NewHeight=NewSize;
> >
> > ShrinkPercent=(NewHeight/bmp.Height)*100;
> >
> > NewWidth=(ShrinkPercent/100)*bmp.Width;
> >
> > }
> >
> > System.Drawing.Image myShrunkenImage =
> >

>

bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero);
> >
> > return myShrunkenImage;
> >
> > }
> >
> > public bool ThumbnailCallback(){return false;}
> >
> >
> > --
> > I hope this helps,
> > Steve C. Orr, MCSD, MVP
> > http://Steve.Orr.net
> >
> >
> >
> > "bob garbados" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >I am trying to create a database-driven photo gallery for a friend with

> an
> > > admin form to upload images... I can upload a file to the web server,

> but
> > > I
> > > want to store the image in a database and I want to resize the image
> > > before
> > > I save it... How do I take the uploaded .jpg and shrink it to a

> thumbnail?
> > > How do I pass the uploaded .jpg to a stored procedure that will store

> the
> > > image as an image datatype in SQL Server 2000? I'm developing this
> > > without
> > > Visual Studio.
> > >
> > > <%@ Page Language="VB" %>
> > >
> > > <script language="VB" runat="server">
> > >
> > > Sub Page_Load(Source As Object, E As EventArgs)
> > > End Sub
> > >
> > > Sub Button_Click(S as Object, E as EventArgs)
> > >
> > >

>

fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho
> > > togallery\NewFile.jpg")
> > > End Sub
> > >
> > > </script>
> > > <html>
> > > <head>
> > > <title>Image Upload</title>
> > > </head>
> > > <body>
> > > <form id="frmUpload" method="post" runat="server"
> > > enctype="multipart/form-data">
> > > <input type="file" id="fsoUploadFile" runat="server"><br/>
> > > <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/>
> > > </form>
> > > </body>
> > > </html>
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
bob garbados
Guest
Posts: n/a
 
      10-29-2004
It's Friday and I've worked too long this week, but I can't figure this one
out... When I try to save the file to the database from my browser pointed
at localhost, it all works fine. When I try to do the same from a remote
machine, it doesn't work. It tries to upload the file from the server's C:\
drive instead of the client's C:\ drive. Any ideas? Is there a setting I'm
missing somewhere?d

"Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here's an article I wrote that describes how to upload images into a
> database and get them back out again.
> http://steve.orr.net/content/asp200307so_f.asp
>
> Also, here's an image resize routine I wrote:
>
> /*shrink the image proportionately so that neither height nor width is

more
> than [NewSize] pixels*/
>
> public Image ShrinkImage(Bitmap bmp, int NewSize)
>
> {
>
> double NewWidth;
>
> double NewHeight;
>
> double ShrinkPercent;
>
> System.Drawing.Image.GetThumbnailImageAbort myCallback =
>
> new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
>
> if (bmp.Width>bmp.Height)
>
> {
>
> NewWidth=NewSize;
>
> ShrinkPercent=(NewWidth/bmp.Width)*100;
>
> NewHeight=(ShrinkPercent/100)*bmp.Height;
>
> }
>
> else
>
> {
>
> NewHeight=NewSize;
>
> ShrinkPercent=(NewHeight/bmp.Height)*100;
>
> NewWidth=(ShrinkPercent/100)*bmp.Width;
>
> }
>
> System.Drawing.Image myShrunkenImage =
>

bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero);
>
> return myShrunkenImage;
>
> }
>
> public bool ThumbnailCallback(){return false;}
>
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
>
>
> "bob garbados" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I am trying to create a database-driven photo gallery for a friend with

an
> > admin form to upload images... I can upload a file to the web server,

but
> > I
> > want to store the image in a database and I want to resize the image
> > before
> > I save it... How do I take the uploaded .jpg and shrink it to a

thumbnail?
> > How do I pass the uploaded .jpg to a stored procedure that will store

the
> > image as an image datatype in SQL Server 2000? I'm developing this
> > without
> > Visual Studio.
> >
> > <%@ Page Language="VB" %>
> >
> > <script language="VB" runat="server">
> >
> > Sub Page_Load(Source As Object, E As EventArgs)
> > End Sub
> >
> > Sub Button_Click(S as Object, E as EventArgs)
> >
> >

fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho
> > togallery\NewFile.jpg")
> > End Sub
> >
> > </script>
> > <html>
> > <head>
> > <title>Image Upload</title>
> > </head>
> > <body>
> > <form id="frmUpload" method="post" runat="server"
> > enctype="multipart/form-data">
> > <input type="file" id="fsoUploadFile" runat="server"><br/>
> > <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/>
> > </form>
> > </body>
> > </html>
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Database drive photo & movie gallery? Daniel Kelly \(AKA Jack\) Digital Photography 3 04-14-2004 09:24 AM
Bookmarks and database driven websites Mark ASP .Net 1 03-03-2004 06:05 AM
database driven menu Brent Burkart ASP .Net 2 01-29-2004 10:18 PM



Advertisments