Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read a jpg from a blob... 1

Status
Not open for further replies.

thatguy

Programmer
Aug 1, 2001
283
US
Hey there folks--

I'm trying to grab a record from an advantage database backend with (supposedly) a jpg stored in a BLOB field. I use SQLEXEC() to pull the records into a table called rdata (which coverts the BLOB field to a General). Then I use the following to write the image out to disk.

Code:
LOCAL lcstr, lnnum
SELECT rdata
GO TOP IN rdata
COPY TO tmpTable FIELDS picture NEXT 1
lcstr=FILETOSTR("tmpTable.fpt")
IF FILE("tmpTable.fpt")
     ERASE "tmpTable.fpt"
ENDIF
IF FILE("tmpTable.dbf")
     ERASE "tmpTable.dbf"
ENDIF
=STRTOFILE(lcFileString, "c:\export.jpg")

I've been told that the images are stored as jpg's, but I get an "invalid format" when I try to open the disk file. Does VFP do something to the image header, or do I need to do something else before writing it to disk?

Better yet, does anyone have a link to some sort of "fingerprint" chart for image files that would let me figure out (a) if these actually are jpg files and if not, then (b) figure out which image type they are?

any help is appreciated..

thanks
-- frank~
 
Frank,
You're currently trying to interpret the complete FPT file as its content including FPT header information and everything else in it. I would even skip the conversion into a general field and just use the "normal" memo field instead. Make sure VFP doesn't perform any codepage transformations (e.g. with SET NOCPTRANS) and then
Code:
select rdata
copy memo picture to xyz.jpg

Volker/
 
or
Code:
select rdata
STRTOFILE(rdata.picture,"xyz.jpg")

Borislav Borissov
 
i'm not sure how to prevent the conversion from blob to general.. i pull the records with a simple select statement over an ODBC cxn:

SQLEXEC(lnh,"select * from data23 where patient = '106377'",'rdata')

and when i browse, the field has been changed to a Gen. is there anyway to stop vfp from making that conversion?

thanks
-- frank~
 
Conversion might happen automatically because of the content of that blob. Still, try either COPY MEMO or STRTOFILE as Borislav suggested.

Volker/
 
with

COPY MEMO rdata.picture TO temp.jpg

i get "Field must be a Memo field." and with

STRTOFILE(rdata.picture,"temp.jpg")

i get a "Function argument, value, count... invalid."

i'm sure there's data in there because when i copy rdata to a disk file, it's shown at around 200k.

thoughts?

thanks
-- frank~
 
ODBC doesn't support a new field types of VFP.
Use a new VFP OleDB driver instead.
BTW this code works for me:
Code:
rcJPG = GETFILE("JPG")
CREATE TABLE Test FREE  (Pct W)

INSERT INTO Test VALUES (FILETOSTR(rcJPG))
BROWSE

GO TOP

STRTOFILE(Pct,"c:\Test.JPG",0)

Borislav Borissov
 
A star for Borislav!

the OLEDB idea worked and i was able to get the image out to a file using

Code:
loc = CREATEOBJECT('adodb.connection')

loc.ConnectionString = "Provider=Advantage OLE DB Provider; Data Source=c:\localdata; ServerType=ADS_LOCAL_SERVER"

loc.Open()

lors = loc.Execute("SELECT * FROM DATA23 where patient = '106377'")

STRTOFILE(lors.fields("picture").Value,"tempy.jpg")

of course, i've never worked with OLEDB before so this'll take some more learning... any good tutorials? is it much better/different than ODBC?

thanks!
-- frank~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top