- 1. Summary
- 2. Step by Step Guide
- 2.1 Registering a new handler
- 2.2 Passing Parameters
- 2.3 Supported events
- 2.4 Additional parameters
- Sample web handler
- SwatInput Attributes for UPLOAD (Subtype)
- 3. Documentation
1. Summary
Support is needed for handling the upload of files and efficiently sending them to the back-end. This involves registering a new web-handler, passing necessary parameters, and managing various upload events and additional parameters to ensure smooth operation. The document also includes sample code for setting up the web-handler and provides alternatives for using the SwatUpload control.
2. Step by Step Guide
2.1 Registering a new handler
In SWAT, a new web-handler must be registered in openedge.properties, similar to AppDataWebHandler, under:
[app.ROOT.WEB]
[app.restbasic.WEB]
A new entry must be added:
handlerXX=path.to.class: /{URL}/{path-param-1}/{path-param-2}
2.2 Passing Parameters
//PATH PARAMS:
poRequest:GetPathParameter ("path-param-1":U)
//QUERY PARAMS:
DEFINE VARIABLE oQueryString AS CharacterDictionary NO-UNDO.
ListHelper:AlternatingListToDictionary(STRING(poRequest:GetContextValue("QUERY_STRING")), "&", "=").
WEB-CONTEXT:URL-DECODE(oQueryString:GetValue("Value")).In the SwatInput or DynFillin, the upload URL must be specified:
- in the
uploadURLattribute - by calling
.setURL()on the upload control from theEventUploadFileAddfunction uploadURLmust include the /web prefix.
2.3 Supported events
Events | Description |
EventUploadComplete | Fires when all files from the list have been uploaded to the server |
EventUploadFileAdd | Fires when the user adds a file to the upload queue |
EventUploadBeforeFileAdd | Fires when the user adds a file to the upload queue |
EventUploadFail | Fires when the file upload has failed |
EventUploadBeforeClear | Fires before the clear event is triggered; can prevent clear event if the function returns the following: return { preventAction: true }; |
EventUploadClear | Fires on clear files; only if not prevented |
EventUploadBeforeFileRemove | Fires before a single file is removed from the list; can prevent remove event if the function returns the following: return { preventAction: true }; |
EventUploadFileRemove | Fires when a single file is removed from the list; only if remove is not prevented |
2.4 Additional parameters
Parameter | Description |
setAutoRemove | enables the mode in which files are immediately removed from the item after downloading has been completed |
setAutoStart | Enables the mode in which files are immediately loaded after selecting |
uploadTooltip | Attribute where you can specify the tooltip values for the different buttons;
Accepts a json string (default: {}), where you can sppecify the different tooltips: browse,upload, cancel, clear |
JSON example:
{"browse": "new label", "clean": "new clean label"}Tooltip labels are also translatable in the common files. Place a custom translation under:
upload.tooltip.<name-of-key>where name-of-key is one of the above 4.
"upload": {
"tooltip": {
"browse": "Search",
"clear": "Remove"
}
},Sample web handler
FileUploadWebHandler.cls is a working example in SWAT.
https://community.progress.com/s/article/How-to-load-a-binary-file-with-webhandlers
Alternatively, the SwatUpload control can be used, if the desired outcome is just uploading files to the backend and assigning the value in a form field.
For the form field, a swat input(left) or dynfillin(right) can be used. Either must be of subtype UPLOAD:
Limitations: events are bound on the form, for all children of type 'upload'; only one upload control should be used in a form.
SwatInput Attributes for UPLOAD (Subtype)
- multipleFileSelection (default:
true) - This attribute defines whether the user can select a single file (false) or multiple files (true) for uploading.
3. Documentation
To find more information, you can check the following documentation.
Field
Back to Use Cases
Back to Build.One Help-Center Home