How to show image from the oracle database in asp.net - asp.net

Hi there i need to show an image stored in the oracle database in (blob format i think).i have retrieved the image from database in dataset = dt.rows[0]["image"].how can convert the image to show it on the page.
Thanks.

In order to display it on a page, you need to serve the image as a separate resource from the web server.
Meaning, your page.aspx will have a tag with a src="your_image.aspx". In your_image.aspx, you need to clear response headers, make sure the Content-type is set correctly (image/jpg or something similar), put the contents of dt.rows[0]["image"] into a byte array and then write it out the binary image with something like Response.BinaryWrite(yourByteArray).
This is just a general outline. Use the googles for details :)

Related

Save image name or path into database

I'm doing an intranet for the employees of the company using ASP.NET and SQL Server, on the profile section i have an upload picture area (image field to show the picture, input to select the file, and the load button), this is working fine, the picture is loading into a folder, but, also i have the text fields where the user adds his info, this is also working great and is saving into the database, what now i want to do is that the user uploads the picture, and finish with all the text fields when he clicks the submit button to send all the fields into the database the name or the path of the picture he uploaded goes into the database too, all my textfields are being saved using an sqlDataSource with insertParameters.
Any idea how to do it?? i would prefer to do it with the front side code, since on the code behind i just have initializing the SqlDataSource1.Insert();
Do not save the images to disk, doing so will result in ugly mess sooner or later.
What you should do is to allow the user to upload the image, resize/crop the image on the server, convert the image to base64 and save the base64 string into varchar(max) column.
Because you are saving only small images(avatars), this solution should work without any problems.
Also when you fetch the image base64 string back from the DB, you can embed it straight into HTML if IE7 is not a requirement. Here is a list of browsers that support Data URI scheme
If embeding base64 into HTML doesn't work out, bulld an ASP.NET page that decodes the base64 string into an image and returns a binary response. Then utilise it in your page like this:
<img src="http://www.example.com/images.aspx?thimageDBrowID=12345" width="20" height="20"/>
If you're using SQL Server 2008 you can look into using FILESTREAM

how to store and retrieve images for user articles

I have a web site in which users post news to site.
so i have two field in my database NewsTitle and NewsBody.
The Newsbody can have images.
What datatype should I use for NewsBody?
I don't want images loaded from image hosting site, I want images save in my database or in my web site's host.
What is the best way to implement this, should I use ajaxcontroltoolkit?
any ideas?
You can set your the datatype as varchar as the filename of your image, since all you need to know when you try to display the image is the filename. (but of course, you must already know the location of this file)
I think u can use ListView and the template field will contain asp:image.you can store the image name in the database and bind the imageUrl through the image directory in your system plus the image name.

how to images store localy from xml using flex 3?

I have one xml link. that link have collections of images(apx 1000 images).
when i flex applications start at the time load all images in locally. then when i need that images then use it.
How i do this... give me some links and logic.
Using flex 3.
Thanks advance.
senthil.
Load the .xml form server or so.
Parse the .xml and create a Map where you store all the image URLs
Place an Image Component on your UI and set the "source" property to the value of the image URL
Flash Plugin will load the image from the URL and will show the image when done.
If you are facing a "SandboxVaiolationException" (or something like that) you need to tell your server to let the request go.
If you want to change the "source" Property of the Image at runtime, just set it after a click oder an other Event. (is no problem)

How can i hide/secure image path?

How can I hide/secure image path in asp.net? I don't want the user see image path directly.
I have googled with my problem and found the following URL:
http://www.codeproject.com/KB/web-security/ImageObfuscation.aspx
On this page it suggests changing the image path like this:
<img ID='ImageControl'
src='ShowImage.axd?Path=<% EncryptString("C:\Images\img.ext", Page) %>'
But if user copy this image src and paste it into their browser with the domain name then it will show image.
There's absolutely no way to achieve this, so no need to waste your time and efforts. As long as the browser can show an image, the user can also directly fetch it.
It really depends on what you are trying to achieve.
If you're trying to stop people linking to your images from another site, then the best option would be to extend the handler you mentioned in your question to only return an image if the Request.Referrer is your own site.
This means that if they did then try and link to the image via your handler, they'd only see a broken image/no image, they wouldn't be able to request the image directly in their browsers, etc.
You should also probably include some sort of time stamp in the encrypted path, and reject requests that come from too long ago - this will again limit the validity of the links:
<img ID='ImageControl'
src='ShowImage.axd?Path=<% EncryptString("C:\Images\img.ext|" + DateTime.Now.ToString(), Page) %>'
Then in your handler:
Dim pathAndTimeEnc As String = ctx.Request.Params("Path")
Dim pathAndTime As String
Dim path As String
Dim timeStamp As DateTime
pathAndTime = Common.DecryptString(pathAndTimeEnc, ctx)
Dim parts = pathAndTime.Split("|"C)
path = parts(0)
timeStamp = DateTime.Parse(parts(1))
Dim fiveMin As TimeSpan = New TimeStamp(0, 5, 0)
If DateTime.Now.Subtract(timeStamp) < fiveMin Then
' Return image.
End If
If you're trying to stop people downloading your images then you're not really going to stop more than the most basic internet user - after all to display the image on your site, you'll need to send a copy of it to the client browser.
However, a couple of possible options to make it harder:
Ensure that the images expire immediately, this means the browser shouldn't keep them locally for that long - however it does mean that none of the images will be cached, and you'll end up with higher bandwidth useage for repeat viewers; if you are using the handler you can do this in code:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
Use CSS to place a transparent 1x1px image over the top of the images on your site - this way if a user right-clicks on the image to save it, they will get the path to the transparent image rather than the one they are expecting (Flickr does/used to do this)
At the end of the day, if you put some content online, then it's very hard to stop the most dedicated "thief" from taking it and using it.
You could do some hack that symlinks the real image path to some (one time) temporary location which is sent to the client. Once the client has received the image, the symlink can be removed; although... what a hack!
How comes the image path is a secret?
You can do this, but it's going to be a lot of work, people are going to be able to get around it, and so there needs to be a really good reason for doing it and you need to recognize that it will never be a 100% solution. It will (at best) be a solution to prevent the non-technical from grabbing the images. (And even they can use Alt+PrintScreen.) And it will take time away from whatever you're doing that actually generates value.
But:
Basically, you can use one-time paths tied to an IP address. When the page is requested, log the IP address and generate custom image paths for that page basically in the form of "http://example.com/images/alsdkjflaskdf" (or "http://example.com/images/getimage?alsdkjflaskdf" if you can't do custom URL handlers) where the "alsdkjflaskdf" part is an encrypted/obfuscated, one-time-only path to the image that's only valid from that IP address, and only valid for a given time period. Once the time is up or it's been used, purge that generated path from your database (or whatever you're using to keep track).
The paths would be
Limited to the IP address
Time-limited
One-time-only
As you can see, it's a pain, and I could easily work around it with wget. Your time is almost certainly better spent elsewhere.
Store the path in a database or xml. Store some kind of unique id each path and rewrite the handler to query the path from the datasource. You can use like this:
< img ID='ImageControl' src='ShowImage.axd?ID=1 %>'
And the path reamain secret :)
Ok. Reread the original post. Try to store the session whitch page has been seen. And if there is no one or not the page that contain the picture You show a black screen. Yes the visitor can see if use the link after s/he saw the page, but until the session is alive. And the link won't work if s/he link to somewhere.

Html Text Editor problem

Hii,
I m using a simple HTML Text editor by providig 'contentEditable' property of a div to true. All the formatting operations are working fine. The problem is when i copy and paste some html contents from somewhere else and try to post to DB the entire content may not post in to db because of the size limitation of the column. Is there any solution regarding this? I m using sql server 2008
What DB are you running?
The only solution to that is to choose a field type and size that's appropriate for the data you are going to be storing there; or if you can't do that save the contents in a file and store the file location in the DB.

Resources