473,657 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

save uploaded image thumbnail to sql db image field

Hi there,
Trying to allow client to upload image, thumbnail it, and save it into
sql table image field.
Code compiles & runs but image cannot be retrieved. any clues what I'm
doing wrong pls !
Dim origImage As System.Drawing. Image =
System.Drawing. Image.FromStrea m(FileUpload1.P ostedFile.Input Stream)

' rewind the input stream to read it again to store the
original image in the database
FileUpload1.Pos tedFile.InputSt ream.Seek(0, SeekOrigin.Begi n)

'make thumbnail

Dim thumbnail As System.Drawing. Image = New
System.Drawing. Bitmap(120, 120)
Dim thisFormat = origImage.RawFo rmat
Dim ms As MemoryStream = New MemoryStream()
thumbnail.Save( ms, thisFormat)
'System.Drawing .Imaging.ImageF ormat.Jpeg)
ms.Seek(0, SeekOrigin.Begi n)

Dim buffer(ms.Lengt h) As Byte
ms.Read(buffer, 0, buffer.Length)

Dim cnn As New
SqlConnection(S ystem.Configura tion.Configurat ionManager.Conn ectionStrings(1 ).ConnectionStr ing)
cnn.Open()

Dim cmd As New SqlCommand("UPD ATE STAFF SET PIC=@img WHERE
STAFF_ID=26", cnn)

Dim ImageContent(bu ffer.Length) As Byte
Dim intStatus As Integer
intStatus = ms.Read(ImageCo ntent, 0, buffer.Length)
Dim prmImage As New SqlParameter("@ img", SqlDbType.Image )
prmImage.Value = ImageContent
cmd.Parameters. Add(prmImage)

cmd.ExecuteNonQ uery()
cmd.Dispose()
cnn.Close()
cnn.Dispose()
Response.Write( "done")
Dec 14 '07 #1
1 3132
Your code that puts image into DB looks good except i do not see anywere
where you actually put a thumbnail image into
variable 'thumbnail', you just create empty thumbnail and never make an
actual picture.
but may be you jsut skiped that code.
then probably youe code that reads image from DB is bad

PS: MemoryStream has GetBuffer method..

That would save you creation of ImageContent byte array.

George
"dodgeyb" <ch***@ctlsoft. comwrote in message
news:b8******** *************** ***********@s12 g2000prg.google groups.com...
Hi there,
Trying to allow client to upload image, thumbnail it, and save it into
sql table image field.
Code compiles & runs but image cannot be retrieved. any clues what I'm
doing wrong pls !
Dim origImage As System.Drawing. Image =
System.Drawing. Image.FromStrea m(FileUpload1.P ostedFile.Input Stream)

' rewind the input stream to read it again to store the
original image in the database
FileUpload1.Pos tedFile.InputSt ream.Seek(0, SeekOrigin.Begi n)

'make thumbnail

Dim thumbnail As System.Drawing. Image = New
System.Drawing. Bitmap(120, 120)
Dim thisFormat = origImage.RawFo rmat
Dim ms As MemoryStream = New MemoryStream()
thumbnail.Save( ms, thisFormat)
'System.Drawing .Imaging.ImageF ormat.Jpeg)
ms.Seek(0, SeekOrigin.Begi n)

Dim buffer(ms.Lengt h) As Byte
ms.Read(buffer, 0, buffer.Length)

Dim cnn As New
SqlConnection(S ystem.Configura tion.Configurat ionManager.Conn ectionStrings(1 ).ConnectionStr ing)
cnn.Open()

Dim cmd As New SqlCommand("UPD ATE STAFF SET PIC=@img WHERE
STAFF_ID=26", cnn)

Dim ImageContent(bu ffer.Length) As Byte
Dim intStatus As Integer
intStatus = ms.Read(ImageCo ntent, 0, buffer.Length)
Dim prmImage As New SqlParameter("@ img", SqlDbType.Image )
prmImage.Value = ImageContent
cmd.Parameters. Add(prmImage)

cmd.ExecuteNonQ uery()
cmd.Dispose()
cnn.Close()
cnn.Dispose()
Response.Write( "done")

Dec 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2211
by: Mark | last post by:
Hi all, I want to be able to resize an image that a user has uploaded. I have the image upload working as well as the image resize. When I go to delete the original uploaded file (I want to replace the uploaded file with the new resized version) I get a "file being used by another process" error. I therefore cannot replace the uploaded image with the new thumbnail. How can I get around this???
1
5969
by: bart plessers | last post by:
Hello, For a while I am working with ThumbsPlus ( http://www.cerious.com/ ) as manager for pics. The benefit of the program is that it stores all kind of information in a central Microsoft Database that easily can be manipulated. A thumbnail of the picture is also stored in de MDB as long binary (jpeg format) I made a small script that extracts all kind of information of the MDB by
0
1040
by: Matt Brelje | last post by:
I have an .aspx page from which users can upload an image. After a file is uploaded, I also save a 60x60 pixel thumbnail of that image. Works great. What I can't seem to do is save a CROPPED thumbnail of that image that does not stretch the image. Does anyone have code (VB please -- no C#) that can do that? Help would be appreciated. Here's what I have:
9
3016
by: Ivan Demkovitch | last post by:
Hi! I would like to know if I can save File on Server using server-side code? For example, I like to create thumbnail images and populate specific directory. Do I need specific permissions to do this? (I use public host) Thanks!
5
4868
by: Brian Lowe | last post by:
My web site accepts uploaded photos and stores them in a SQL table as BLObs so they never touch the filesystem. I have a way to create a thumbnail version of the uploaded image and store that in the db too, again without touching metal. I need a way to overlay some text on the image but I'm stuck. All the help I find uses files in the filesystem, and when I try to convert the example to my imagestream model it fails and I can't...
2
7225
by: NATO24 | last post by:
Hello, I am trying to write a sub routine that I can pass a posted (image) file to. That routine will save the original file, then create a thumbnail and save it. When I try to create the image with the posted file, I get an error saying file type HttpPostedFile cannot be converted to an Image. When I save the original and try and use the FromFile method to create the thumbnail, it says that the file is already in use. Any ideas?
3
3102
by: neovantage | last post by:
Hey all, i have created image by mixing logo and the original image. It create image and show in the same window. I have done 3 steps for this. First i upload an image to my server by using move_upload_file, then i resize it using class "thumbnail.class.php" My next step was to embed company logo in it(which i already done) and save new embedded logo image to the path where i first upload the original image i mean i want to overwrite...
7
9528
by: sandeepk84 | last post by:
Hi all... I have file upload option in my web application. I use Struts 2. I wanted to show a preview of the uploaded file to the user. The uploaded file can be of any type like Image(png,jpeg,gif,etc.), PDF,doc,txt,ppt,xls,html,etc. As of now the user has to download the file if he wants to see it which is not a good idea.
1
4876
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop program,which can upload many file in folder.problem is,am unable to save my file name in to database.because i used same name for all input file type as file. i dont know get name of file.below i presented my coding for ur view.fed up with my coding..pls...
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.