|
|
I can load the image to the database but cant retrieve it to display it in a web page.
|
|
|
|
To store/retrieve this sort of data within TSQL scripts you have to use the
WRITETEXT and READTEXT commands rather than standard INSERT/SELECT statements.
These are documented, with examples, in the books-online but are basically a
real pain to use. There are more manageable commands available from within the
relevant programming languages - e.g. RDO and ADO from VB/C can use GetChunk
and AppendChunk commands - but you still have to manage the image/text
chunks/blocks of data at a time. About the only upside of storing this sort of
data within SQL Server is that it can be kept transactionally consistent with
the other data.
For native ODBC access use the SQLPutData and SQLGetData commands.
If you just want to insert/retrieve an entire image/text then look at the
TEXTCOPY program (textcopy /? for parameters) in the \BINN directory. It
is a command-line program along the lines of BCP.
There is a very useful (free) dll available from
http://www.chriscrawford.com/DBImage (courtesy of Chris Crawford). It has
three functions:
GetImage Used for getting an image from the database
StoreImage Used to send an image to the database
GetWebImage Used to send a DB image to a browser
If transactional consistency doesn`t matter, or can be achieved
programmatically, then it is easier to store the data outside the database as
an ordinary file. Within the database just hold a UNC pointer to where the
file is held. This usually makes it much easier to display/edit the data as
the name can simply be passed to whatever tool is doing the manipulation.
|
|
|
|
many thanks who ever you are? it seem lots of work to read an image from a database. I will try the methods you suggested
|
|
|
|
hi rob...
second option :
in file test.html, put this code :-
<img src="image.asp?id=1">
then, in same directory, make file image.asp
and put this code :-
<%
Response.ContentType = "image/gif"
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
id = Request.QueryString("id")
`checking the data exist or not
`Server Name=test
`SQL Server database name=test
cme = "DRIVER={SQL SERVER};SERVER=test;UID=sa;pwd=;DATABASE=test"
`field ImageItem is image datatype in SQL Server.
cmdsql = "SELECT ImageItem from EQUIPMENT WHERE id =`"&id&"`"
set rs = Server.CreateObject("adodb.Recordset")
rs.open cmdsql, cme
Response.BinaryWrite rs("ImageItem")
Response.End
%>
it works fine for me.
no DLL consider for this option.
feel free to visit http://www.vss.com.my
|
|
|
|
|
|
the problem with this method is it flushes out all your code.
|
|
|
|
from rob :
the problem with this method is it flushes out all your code.
my answer :
flushes !, what you mean by that.
as i`m concern, this method will be getting the image datatype
from SQL Server.
very practical code.
i`m using it until now.
|
|
|
|
|
|
Both of the previous replies will work for you. The component sounds nice, but many times you may not be allowed to install components to the server. Or maybe you are on a tight budget and so do without components when possible. In which case, the second method suggested is all you need. Here is an article that provides even more detail regarding the answer you already got. Part 2 is specifically what you are looking for.
Part 1
http://www.superdotnet.com/show_article.aspx?pkID=81
Part 2
http://www.superdotnet.com/show_article.aspx?pkID=83
I can`t find Part 3, which I`d love to get my eyes on!
|
|
|
|
|
|
Hi there,
Is it possible to put an image into the database in a similar way?
Thanx!
|
|
|
|
|
|
|
|
|
I just wanted to follow up to say that most people don't store images in the database. Instead, they just store them in the filesystem as a normal file and only save information about the file in the database. It makes for simpler code, and there usually are not any performance reasons to store large binary chunks in the database. Plus, it allows you to work with your image files natively in the filesystem if you want/need.
|
|
|
|
|
|
I understand what you're saying but I'm particularly interested on this approach because we are about to develop an e-business web site to sell photos!
For security reasons this seems to be the best way to do it, don't you think?
|
|
|
|
hi dio,
why don't you try change the file content into binary format and keep it in binary field (database). then, you review it using code that can convert binary into image or whatever needed. I'm believe there is a way to do this but keep try and try. Hopefully you'll find it.
smile while programming.
<Added>
or,
maybe you can using PHP code because PHP code can help you on saving your record in database. However, I'm suggesting you make another database (MySQL) to store an image because it will make your main database (MS SQL) working more faster. If you store on same database, maybe it'll effect your main process and memory. Keep going to try it. You need to know various code other than ASP. Check it out PHP and MySQL. I'm sure it will help you to make e-portal/business.
Please make sure your IIS can support PHP compiler, check it out on IIS configure with PHP.
refer this link regarding on PHP and MySQL :-
http://www.atalasoft.com/products/imgxasp/docs/Database.html (Guide to insert image)
http://www.php.net (PHP Library/Source)
http://www.mysql.com (MySQL Database)
http://www.sqlyog.com (MySQL Control Interface)
http://www.apache.org (HTTP Server) @ using IIS
GOOD LUCK.
|
|
|
|
|
|
dio, saving images to the filesystem rather than in a database does not present any security issues if done correctly. You can store all the images in directories that are outside the webroot. This way the images cannot be directly linked to. You can serve the images in your web pages using a script that you pass the filename to, then it reads the image server-side and streams back as an image.
I'm not saying DO NOT store in the database. I'm just saying that in my experience, I've found most people opt not to store them in the database. Honestly, I'm not sure of all the reasons why. It adds complexity to your application for one thing.
|
|
|
|
|
|
hey there,
I have already achieved what I wanted except for one thing, that is, save the image in the DB without using a third party component. Still, it seems this isn't possible on classic ASP.
thanx
|
|
|
|
hi dio,
As I said, please using PHP Code which can help you much better to insert image file into database. you can separate your image database using MySQL instead of using SQL Server. I'm sure your system running on web-based and database referring to SQL Server but if your IIS (web server) had been set running ASP and PHP code properly, you can implement ASP and PHP code into your system. don't wait for any approach to come you just like that. be a good web database programmer need to implement many technique to ensure the result can be view and make our client happy ever after. hehehehee. smile man while learning.
example :
in file abc.asp, having form code :-
<form name="worldForm" action="insertImage.php">
....
....
....
</form>
|
|
|
|
| This 16 message thread spans 2 pages: [1] 2 > > |