IFS to BLOB

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
soa
Posts: 339
Joined: Mon Dec 07, 2015 3:15 pm

IFS to BLOB

Post 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?
atostaine
Posts: 696
Joined: Wed Jan 20, 2016 7:38 am

Re: IFS to BLOB

Post 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
Art Tostaine
soa
Posts: 339
Joined: Mon Dec 07, 2015 3:15 pm

Re: IFS to BLOB

Post 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.
atostaine
Posts: 696
Joined: Wed Jan 20, 2016 7:38 am

Re: IFS to BLOB

Post by atostaine »

when you retrieve the blob it is written to the ifs. we grab them there and put them where we need them.
Art Tostaine
Post Reply