473,671 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving/Decoding base64 string from database to image and display in image control

1 New Member
Database backend:Postgre SQL
Database Name: MoviesDirectory
Table Name: picture
Column: img DataType:bytea

First, I store my uploaded images which may be either .jpg,.gif,.png with the following codes:
Expand|Select|Wrap|Line Numbers
  1. ....
  2. ....
  3. ....
  4. if (FileUpload1.PostedFile.ContentLength != 0)
  5.             {
  6.                 byte[] b = new byte[FileUpload1.PostedFile.ContentLength];
  7.                 FileUpload1.PostedFile.InputStream.Read(b, 0, b.Length);
  8.                 string basestring = System.Convert.ToBase64String(b, 0, b.Length);
  9.                 TextBox1.Text = basestring;
  10.             }
  11. ....
  12. ...
  13. ...
  14. ConnStr = ConfigurationManager.ConnectionStrings["connect2MD"].ToString();
  15.             Conn = new NpgsqlConnection(ConnStr);
  16.             Conn.Open();
  17.             try
  18.             {
  19.  
  20.                 strSQL = new StringBuilder();
  21.                 strSQL.Append("INSERT INTO picture(img) VALUES (@img)");
  22.                 command = new NpgsqlCommand(strSQL.ToString(), Conn);
  23.  
  24.                 param = new NpgsqlParameter();
  25.                 param.ParameterName = "@img";
  26.                 param.Value = TextBox1.Text;
  27.                 command.Parameters.Add(param);
  28.  
  29.                 command.ExecuteNonQuery();
  30.  
  31.  
  32.             }
  33.             catch (Exception ex)
  34.             {
  35.                 throw (ex);
  36.             }
  37.             finally
  38.             {
  39.                 if (Conn.State == ConnectionState.Open)
  40.                     Conn.Close();
  41.             }
  42. ...
  43. ...
  44. ..
  45.  
The question is that - I want to retrieve back that I have already stored the base64 string and display it with the IMAGE CONTROL on my form.
Nov 11 '10 #1
0 1252

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3226
by: Magnus | last post by:
Hi, I'm programatically posting an image using multipart/form-data. It sends to the server OK, but when I try to view it in the browser, it is still in the base64 string I sent it as: /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUG etc.... I've been through the form I built over and over: string PostData = ""; PostData += "-----------------------------7d41fb3081216"; PostData += "\r"; PostData += "\n";
2
17131
by: marcelo szwarc via .NET 247 | last post by:
I already broke my head, searched everywhere. PLEASE I NEED YOUR HELP! Do you know how can I convert an image file( like a gif or jpeg ) to a Base64 string? I need to use it to send embedded image files through email. I only need this to finish my app. Thank you!!! -------------------------------- From: marcelo szwarc ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/)
27
15032
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image from it. Any help will be highly appriciated. Thanks
7
7918
by: Neo Geshel | last post by:
Greetings. I have managed to stitch together an awesome method of posting text along with an image to a database, in a way that allows an unlimited number of previews to ensure that text and image are perfect before submission. This involves converting any uploaded image to a Base64 String and holding that in a hidden form field until either the post gets submitted to the database or the image gets replaced with another one. I...
2
1212
by: Jennyfer Barco | last post by:
Hello, I need to decode a string that is encoded on Base64 format. The string is a GIF image, so it's very long and weird data. Do you have an example on how to do this? Thanks in advance Jennyferd Barco
3
5233
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from database and display it in a Image web control dynamically(at runtime). The process after being displayed in the web control, user click insert/add button, it converts the image(jpeg) file to bytes and store it the database with Image or VarBinary...
7
5399
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed to show the image, and an image.php page that accesses the database, retrives the image data, and then (theoretically) prints the decoded data to the page. below is the view.php page code: problem area the img tag src no
1
2983
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title>
10
7261
by: sandeepdhankar10 | last post by:
hi!!! i need some help from the Experts Like u people.. i m creating a applictaion that transfer images to the webservice which store in server memory temp.. and retrive back those images on other location at the same time.. i successfully created the applictaion .. using some serialization concept (BInary Formatter).. But the main issue is that .. it isworking very slow. it take too much time around 30 - 40 sec to display image on the...
5
4229
by: smclellan86 | last post by:
Hi Everybody, I've been working on this challenge for a while now without much luck. What I'm attempting to do is split a MIME byte response into its individual images. I am given the boundary to split on in the HTTP header but when I attempt the following code it doesnt work. If anybody has some suggestions on what I should attempt here I would greatly appreciate it. 'boundary to split on Dim boundary as string = _ "boundarystring" ...
0
8483
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
8825
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8676
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6237
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
4227
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
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
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
2062
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.