Nathan,
Here is the bog standard technique which avails itself of the Net.data
file upload feature.
In this case it is assumed that the server-side cgi will run under the
default QTMHTTP1 profile.
The Net.data INI file associated with the request contains the directive
DTW_UPLOAD_DIR /upload
QTMHTTP1 must have *RWX authority to this upload directory.
Net.data will generate an unwieldy unique name for the uploaded file
based on various elements obtained from the request.
This macro performs some additional functions once Net.data has place
the file in the Net.data upload directory.
The macro moves and renames this uploaded file to another directory
which is specifically defined in this case by a variable named
upload_dir. To achieve this some authority issues must be attended to.
In order for the move to succeed QTMHHTP1 must have *OBJMGT authority to
the Net.data upload directory, in this case /upload
Before renaming, this macro always attempts to delete any existing file
of the same name ( from a prior upload)
In order for the delete to succeed QTMHHTP1 must have *OBJEXIST
authority to the previously upload file.
Both these authority needs can be met by providing that the owner of the
Net.data upload directory has *OBJMGT and *OBJEXIST authority. Note that
since this directory already exists then this owner will probably not be
QTMHHTP1.
However the uploaded file will be owned by QTMHHTP1 who will inherit the
*OBJMGT and *OBJEXIST rights from the owner.
As an extra feature, this macro responds with a link that the user can
use to download the uploaded file to verify the process. Since this is
not a cgi link then for this to succeed QTMHHTTP or *PUBLIC must have
*RX authority to the final repository, in this case /wwwserv/tmp.
%define { upload_dir = "/wwwserv/tmp" %}
%html(macro) {
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="doload">
<p>Enter the name of the file to upload
or use the browse button to select one:
<br><INPUT TYPE="FILE" NAME="fname">
<br><INPUT TYPE="Submit" value="Upload">
</FORM>
%}
%FUNCTION(DTW_SYSTEM) Chgaut() {
%EXEC { CHGAUT.CMD OBJ('$(fname)') USER(QTMHHTTP) DTAAUT(*RWX) %}
%}
%FUNCTION(DTW_SYSTEM) MoveFile() {
%EXEC { MOV.CMD OBJ('$(fname)') TODIR('$(upload_dir)') %}
%}
%FUNCTION(DTW_SYSTEM) RenameFile() {
%EXEC { RNM.CMD OBJ('$(filename)') NEWOBJ('$(filein)') %}
%}
%html(doload) {
@dtw_lastpos("/",fname,l)
@dtw_concat(upload_dir,@dtw_rsubstr(fname,l),filename)
@dtw_lastpos("-",fname,l) @dtw_add(l,"3",l)
@dtw_substr(fname,l,filein)
@Chgaut()
<br>debug: MOV.CMD OBJ('$(fname)') TODIR('$(upload_dir)')
@MoveFile()
@dtw_concat(upload_dir,"/$(filein)",newname)
%if (@dtwf_rexists(newname)=="Y") @dtwf_remove(newname) %endif
<br>debug: RNM.CMD OBJ('$(filename)') NEWOBJ('$(filein)')
@RenameFile()
<p>File has been uploaded to $(upload_dir)/$(filein)
<p>Click here to <a href="$(newname)" target="_blank">
download the file</a> to verify the upload
%}
If you ignore the move and rename then it should be obvious that
Net.data makes this a trivial process.
Forget easy400, why roll your own when IBM already provide it free and
easy.
Cheers, Peter
-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx]
On Behalf Of Nathan Andelin
Sent: Saturday, 5 April 2008 8:06 a.m.
To: web400@xxxxxxxxxxxx
Subject: [WEB400] File Attachment Utility
Hi Folks,
I could use some advise on a File Attachment Utility. I'm just now
working on it. A couple screen shots are at the following link:
http://www.radile.com/rdweb/apps/ptl/xat160/attach.html
The idea is to place an "Attach" tab on any standard maintenance screen
to attach files to any other entity. The screen shots show a Person
maintenance screen, but the idea is to be able to attach files to
anything I may have in my database. In a project maintenance screen,
you might attach various documents to a project record.
A utility, in other words. In "view" mode you can browse and open
attachments. In "add" mode you can browse the network to upload and
attach files to things.
This utility is working except for the most important part; uploading
and storing files in the IFS. That's where I could use some advise.
I've downloaded the FUPLOAD utility from www.easy400.net and looked at
the RPG source code. FUPLOAD has it's own user interface, so it would
take some work to make it interact with my utility. Nevertheless I
appreciate Giovanni Perotti for his open-source work. Before I charge
forward with that, are there any other suggestions?
Thanks,
Nathan.
As an Amazon Associate we earn from qualifying purchases.