Page 1 of 1

IFS to BLOB

Posted: Wed Apr 05, 2017 4:53 pm
by soa
I have images stored in the iSeries IFS which I wish to retrieve in my Server Module as BLOBs. Is there a simple way of converting a file path into a blob?

Re: IFS to BLOB

Posted: Thu Apr 06, 2017 4:33 am
by atostaine
I copied together a function from a lot of older sources. This could be nicer, but it works.

Basically you set the value of the blob to the path. I ran my locally on a PC with the IFS mapped to the L: drive.

Code: Select all

FUNCTION OPTIONS(*DIRECT)

DEFINE_COM CLASS(#prim_alph) NAME(#wkDire)
DEFINE_COM CLASS(#prim_alph) NAME(#pDir)
DEFINE_COM CLASS(#prim_alph) NAME(#pFile)

DEFINE FIELD(#w_name) TYPE(*CHAR) LENGTH(50)
DEFINE FIELD(#w_prefix) TYPE(*char) LENGTH(16)
DEFINE FIELD(#w_suffix) TYPE(*char) LENGTH(3)
DEFINE FIELD(#w_date) TYPE(*char) LENGTH(8)
DEFINE FIELD(#w_time) TYPE(*char) LENGTH(6)
DEFINE FIELD(#w_isdir) TYPE(*char) LENGTH(1)
DEFINE FIELD(#w_size) TYPE(*dec) LENGTH(9) DECIMALS(0)

DEF_LIST NAME(#directory) FIELDS(#w_name #w_prefix #w_suffix #w_date #w_time #w_size #w_isdir) COUNTER(#listcount) TYPE(*WORKING) ENTRYS(*max)

CLR_LIST NAMED(#directory)

#pDir := 'L:\Images\'

* Set image type for Database
#pFile := 'EMPLOYEES'

USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(GET_DIR #pDir) TO_GET(#r_status #r_winsts #directory)

IF (#r_status ^= OK)
RETURN
ENDIF

SELECTLIST NAMED(#directory)

IF ((#w_name.upperCase.Contains( '.JPG' )))
#wkDire := #pDir + '\' + #w_Name
#audFnm := #pFile
#audFid := #w_prefix
#audSeq := 1
* this is blob field
#lwiImage := #wkDire

CHECK_FOR IN_FILE(lwimages01) WITH_KEY(#audFnm #audFid)

IF_STATUS IS_NOT(*equalKey)
#audId := *AUTONUM08XXXNXTID2
INSERT FIELDS(#audID #audFnm #audFid #audSeq #lwiImage #createdby #createdDt #createdTm) TO_FILE(lwImages)
#std_Count += 1
ENDIF
ENDIF

ENDSELECT


MESSAGE MSGTXT('Total Images in Directory ' + #listCount.asString)
MESSAGE MSGTXT('Total Images added ' + #std_Count.asString)
Art

Re: IFS to BLOB

Posted: Thu Apr 06, 2017 8:40 am
by soa
Thanks for that.

I know that I can get ifs file and put into a blob field in a file and then fetch it out again to create a blob that I can send out as a return value of my server module but it doesn't seem very elegant! An intrinsic on a blob field .CreateFromFilePath() would be nice.

Re: IFS to BLOB

Posted: Sat Apr 08, 2017 2:38 am
by atostaine
when you retrieve the blob it is written to the ifs. we grab them there and put them where we need them.