DEV Community

Peter + AI
Peter + AI

Posted on

πŸ“ Mastering File Operations in Uniface: A Complete Guide to fileload

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}
Enter fullscreen mode Exit fullscreen mode

πŸ”§ 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
Enter fullscreen mode Exit fullscreen mode

🌐 Web File Upload

fileload/web "UPLOADNAME.ENTITY.MODEL", $1
filedump/raw $1, "downloads/file1"
Enter fullscreen mode Exit fullscreen mode

πŸ“„ 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
Enter fullscreen mode Exit fullscreen mode

πŸš€ 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)