Page 1 of 1

BLOB to store IFS files

Posted: Fri May 23, 2014 8:07 am
by gbroggi
Hello there,

maybe as many of you I'm building an application to upload and download PC files to the iSeries, but I would like to store data into a database table instead of the IFS.
I created a phisical file named ATTACH0F with a simple record format:

ATID - DECIMAL (15,0) Primary key
ATTITLE - Attachment Title
ATFILE - File name. Example /tmp/items.xls
ATBLOB - binary large object to store file

My RPG program shows a grid listing ATTACH0F contents, then you can choose to upload new files or download the ones listed:

Upload to server - If the user needs to add files I placed a button to shown the FileUpload widget to copy files into IFS, then my RPG takes those files and copy them into ATTACH0F and delete them from IFS once the copy is compled.

Download from server - On each grid (subfile) row I placed a button to download the file, but here comes the problem: I need to copy back the file from ATTACH0F into the IFS before using pui.download API.
How can I work it out when the user press the download button?

I hope the problem is clear enough. Thank you for comments

Giovanni

Re: BLOB to store IFS files

Posted: Fri May 23, 2014 9:38 am
by David
The "pui.download()" API works by calling an exit program that you write before downloading the file. The exit program can copy the file from the BLOB to the IFS, and then tell the download API where the IFS file is. It can even clean up the IFS file afterward.

See here:

http://www.profoundlogic.com/docs/displ ... DNLEXIT%29

This is called twice for each download. Once before the download, and once after the download. The 'timing flag' parameter tells you which one it is. When the exit program is called before the download, it can copy the BLOB contents to a temporary IFS file, and then it can set the 'ifs directory' and 'ifs stream file' parameters to tell the downloader where the file is located. The downloader will then output the file to the web browser. It will then call the exit program again, which can look at the 'timing flag' and delete the temporary IFS file.

Re: BLOB to store IFS files

Posted: Fri May 23, 2014 11:16 am
by gbroggi
Thank you David.

The pui.download "id" attribute rapresents the file name to download and it's passed as input to the exit program; but in my scenario the database file primary key is an anonymous counter and not the file name. Please see attached file.
ATTACH0F.xlsx
(10.9 KiB) Downloaded 424 times
If I code something like pui.download(id: items.xls) I won't be able to access my table ATTACH0F
I need to chain the database file by ATID field, copy the blob contents to a work directory and then activate the download.


Giovanni

Re: BLOB to store IFS files

Posted: Fri May 23, 2014 11:56 am
by Scott Klement
The id doesn't need to be a filename. It can be any value you want to pass between your display file (where you're calling the pui.download API) and the exit program.

In your case, I'd think you'd want to put the ATID field in the id. The exit program can then use this to get the data out of the blob and put it into a temp file in the IFS. Then you can download that file, and delete it when it's finished.

Re: BLOB to store IFS files

Posted: Fri May 23, 2014 12:19 pm
by gbroggi
Thank you Scott, I'll try.

In my opinion it's better to keep all information into database tables because of a better data integrity. It sounds strange to me having a file recording for example customer invoices coming from the ERP and the related documents (pdf, doc, etc..) on the file system.
That's why I'm doing this way and the pui.download() is a workaround. In fact I'd prefer to have something to copy immediately into a database file instead of transit from IFS.

Regards
Giovanni