Edit

Upload

In iSeries2web there is a build in upload function.
It uploads files to the webserver in a isolated location. Protected from unautorized download.

Edit

How it works

  1. The upload function uploads the file to the server in a temporary space together with up to 5 keys and a description to identify the file later.
  2. The file's mime definition (the type) is then testet against autorized mime definitions on the iseries host.
    1. If autorized, a unique key is generated, and keys to identify the file again are stord in a archive.
    2. Then the file is stored on the webserver with the unique name and a message is sendt to the upload window.
  3. If not autorized a message is sendt to the upload window and the temporary file is discarted.

When the file is uploaded it is saved with a unique key and name. The key is used to retrive the file again and the unique filename allows for uploading of files with the same name without conflicting.



Fig 1. Screendump of the upload dialog.
Image

Edit

Keys

The dialog is hardcoded to upload to a master key. E.g. you set the main index for the uploaded file. ex. "Customer Images" or "Public Helpfiles" etc.
After this main "Key" you can set 5 additional keys, ex. CustomerId, InvoiceID and OrderID.
It is only the values that are stored, not the "names" of the keys.

You will know that on master key "Customer Images", you have chosen to set key1 as the CustomerID, and key2 as the InvoiceId. e.g. it's up to you to create a search program that finds the correct entry. This entry has the unique name of the file, that you need to retrive it again.

Edit

Implementaion

The simplest implementation is create a list of the uploaded files (with certain key combinations) together with a link to retrive the file again and a button (or link) to upload new files.

Edit

Displaying the uploaded files

The information for each uploaded file is located in a file named SSUPL004P, you can loop through, the file with servername + your main key, and optional keys.

ex. The putxmlrec for at list.

PutXmlRcd('lst_files':''                      

+ xmlA('ssfilename':ssfilename)
+ xmlA('ssfiledesc':ssfiledesc)
+ xmlD('ssfiledate':ssfiledate)
+ xmlA('showfile':GenIdTag(xmlN('id':idupl004)
+ XmlA('function':'dsp_arc')
))

As you can see the in the example it uses some informtion from the SSUPL004P file to display the filename, the description (entered by the user at upload time) and the date for the upload. There are more fields available, check the file description. The link is quite simple to use, just generate a tag with the unique id, and add the function "dsp_arc" to the tag, then iseries2web will take care of the rest.

iSeries2web also includes a series of standard icons you can use to make the list look nicer. To use the icons there is a file called SSUPL002P that holds the icons and a reference to the MIME type of the uploaded files. so the simplest way to get it is to chain with the mimetype (stored with the key in SSAPD004P) and use the path stored in SSAPD002P.

If ssIconName = *Blanks Or ssFileCont = *Blanks; 

Chain (ssMime) ssupl002l1;
EndIf;

and add

+ XmlA('img':'images/upload/'+%trim(ssIconName)) 


to the putxmlrec.



Edit

Uploading new files

To upload files you must provide iseries2web with a masterkey and the optional 5 extra keys. to do this you must create a link that calls a CMS code with your keys, this way you can control that the upload will be saved in the correct context. E.g. you create a "hardcoded" set of keys and send them to the upload control, this control will then upload the file together with the keys and the description.

You can create more than one "upload" link to upload the same file with different keys.

Here is an example on how to create a CMS code (that lasts for 60 minutes and have the keys for the upload).
The key is normally retrieved from the screen. Imagine that on a customer screen, you would have a customer id. and an icon or a link to display the list of files. This link would have the needed keys.

Begsr Crt_Upload;   

ssmainkey = 'CustomerFiles';
sskey1 = rtvVarA('cus001id');
sskey2 = ' ';
sskey3 = ' ';
sskey4 = ' ';
sskey5 = ' ';
cmscode = RandomWord;
setll (fs_svrnam:cmscode) ssapd015p;
dow %equal(ssapd015p);
cmscode = RandomWord;
setll (fs_svrnam:cmscode) ssapd015p;
enddo;
cmsvrnam = fs_svrnam;
cmperm = 'E';
cmdate = now('d');
cmtime = now('t');
cmexpire = %timestamp() + %minutes(60);
cmsparm = ' '
+ xmlA('mainkey':ssmainkey)
+ xmlA('key1':sskey1)
+ xmlA('key2':sskey2)
+ xmlA('key3':sskey3)
+ xmlA('key4':sskey4)
+ xmlA('key5':sskey5);
write rssapd015;

EndSr;
After this just add this to you main flow.

Exsr Crt_Upload;
CustomerFiles = cmscode;

And create the xml for the link.

Begsr Crt_Header;                        

PutXmlRcd('dsoData':' '
+ xmlA('arccustomer':CustomerFiles)
);
EndSr;


in your HTML you add the necessary code to display the list and add the link to upload.


<form method="POST" action="i2w.aspx" name="form0">

<table>
<tr>

<td>Upload New file&nbsp; <img src="/images/icons/page_add.png" style="cursor:pointer" onclick="nonModal('i2wupload.aspx?[[arccustomer]]',500,300)"></td>
</tr>
</table>

<table id="lst_files">
<thead>
<td></td>
<th align="left">[[l_ssfilename]]</th>
<th align="left">[[l_ssfiledesc]]</th>
<th align="left">[[l_ssfiledate]]</th>
</thead>

<tr class="listitem" altclass="altlistitem">
<td><a href="i2w.aspx?[[showfile]]"><img width=25 height=25 src=[[img]]></a></td>
<td>[[ssfilename]]</td>
<td>[[ssfiledesc]]</td>
<td>[[ssfiledate]]</td>
</tr>
</table>
</form>