Set Up File Upload
[EE] In this example, we will upload some files and associate them with employees from the pjdata.employee table.
The operation we used, All Employees, selects some basic fields from the employee table and also includes a derived
field. Derived Fields called d_upload_files.
Create the derived field descriptor for d_upload_files.
Here is the File Upload All Employees operation without associations:
After creating the derived field, we need to create FDs for the employeefiles table. The employeefiles table will hold the
files associated with each employee. In the Connections screen, click on the "Edit FD's" link next to the relevant
connection and navigate to wowsamples.employeefiles.
Under table functions, click the "Create FD's" link. Edit the FILE_NAME, MIME_TYPE and FILE_SIZE field descriptors and
set their usage IDs.
FILE_NAME: -200
MIME_TYPE: -190
FILE_SIZE: -210
NOTE: If going against MySQL, WOW sometimes recognizes BLOB fields as SQL Type VARBINARY. For file upload to
work correctly, we need to use the Blob SQL Type as shown below.
Next, create an associated operation to insert the related files into the database. In this case we have already set
the usage ids for FILE_NAME, MIME_TYPE and FILE_SIZE and have set the ID field to auto increment. These fields will
be filled in automatically when we try to insert a new file. Now, we need to associate the file with a particular employee,
so we will default the employeenum field to ??EMPNO which fills in each employee's number from the employee table.
The associated insert operation will be a standard insert statement except for a few property changes. First, we only
want to insert one file at a time so we need to change the operations row count to 1 instead of 50.
Now that we have set the required usage ids for the other relevant fields, we want to only show the blob_file field when
inserting. To do this we must add the blob_file to the details property of the DisplayColumns property group:
DisplayColumns{details:blob_file;}
After we have inserted the operation, we then need to associate with the d_upload_files field. Open the d_upload_files
FD and set the Associated Operation to the upload file association operation that was just created.
Run the Employee operation and click on the "Upload File" link.
Use the browse button to find the file, image, or document that you would like to upload to the blob field and then click
the insert button. If your BLOB_FILE field does not have the [Browse...] button next to it, check the FD and ensure that
the Display Component is set to "File Upload" as in the image below:
Now, you will have a file that is associated with the employee and stored in a blob field.
Here is the blob file upload file explorer screen.
Here is the filled blob file upload field.