Working with files is a fundamental part of any application development, and Uniface 10.4 provides a powerful and versatile command for this purpose: fileload. This comprehensive guide will walk you through everything you need to know about loading files into your Uniface applications. π
Note: This article is based on the official Uniface Documentation 10.4, with assistance from AI to structure and present the information clearly.
π― What is fileload?
The fileload
statement is Uniface's versatile command for copying file contents into fields or variables. Unlike its counterpart lfileload
, it uses locations specified in the assignment file to locate files, making it more flexible for enterprise applications.
π Basic Syntax
fileload {/text | /raw | /image | /web } FilePath, Target {, UnicodeFormat | CharSet}
π§ Qualifiers: Choose Your Loading Strategy
Uniface offers four different qualifiers to handle various file types:
π /text (Default)
Translates raw data to the system character set or specified Unicode format. Perfect for text files and documents.
πΌοΈ /image
Designed specifically for image files. Adds an initial hash character (#) as an indicator and performs no further conversion.
β‘ /raw
Reads raw data without the hash character prefix. Ideal when you need unmodified binary data.
π /web
Handles files uploaded via browser in Web Application Server components. Essential for web-based file uploads.
π§ Parameters Breakdown
Parameter | Type | Description |
---|---|---|
FilePath | String | File path (max 255 bytes) - can be in zip archives |
Target | String | Destination field, variable, or parameter |
UnicodeFormat | String | UTF-8, UTF-16, UTF-32 variants |
CharSet | String | Overrides $SYS_CHARSET |
π Return Values and Error Handling
Smart error handling is crucial for robust applications. The $status
variable provides valuable feedback:
- β₯0: Success! Number of bytes loaded π
- -1: I/O error occurred π«
- -4: Cannot open file π
- -16 to -19: Network errors πβ
π‘ Pro Tips and Best Practices
π Unicode and BOM Handling
Uniface automatically detects Unicode Byte-Order-Mark (BOM) and handles character encoding intelligently. If no BOM is found, it falls back to your specified character set.
π XML File Special Treatment
When loading XML files, Uniface automatically:
- Removes encoding attributes from XML declarations
- Converts data to UTF-8
- Maintains XML structure integrity
π‘οΈ File Path Best Practices
- Keep paths under 255 bytes
- Use generic separators:
/
,\
, or[a.b]
- Avoid wildcards (except with $dirlist functions)
π― Practical Examples
πΈ Loading Images
fileload/image "flags/%%$language%%%.bmp", FLAGFIELD
π Web File Upload
fileload/web "UPLOADNAME.ENTITY.MODEL", $1
filedump/raw $1, "downloads/file1"
π Text File with Status Check
trigger detail
fileload "/home/central_park/textfiles/text.txt", TEXTFIELD
message "%%$status%%% bytes of text loaded into TEXTFIELD field."
end
π Conclusion
The fileload
command in Uniface is more than just a file readerβit's a comprehensive solution for handling various file types in enterprise applications. Whether you're dealing with text files, images, or web uploads, understanding these qualifiers and best practices will make your file operations more reliable and efficient.
Ready to implement robust file handling in your Uniface applications? Start experimenting with these examples and watch your file operations become more powerful! πͺ
Top comments (0)