Document Fields

Document fields are essential for storing files in your database, and understanding how to configure them effectively can greatly enhance your application's functionality and user experience. In this guide, we will cover the basics of document fields, how to customize their size and allowed extensions, and how they appear and function within an MVC webpage. With the help of visual aids, you will learn how to upload, edit, and manage files within your application.


The document field

  • A document field is a database field that holds a file. In the SQL database itself, in the table it is created, the document is saved as a combination of two fields: the name given to the field and a foreign key to the DOCUMS table, where all uploaded files are saved as an encoded byte array, among other pieces of information, such as file size, extension, table and field they belong to.

Document field customizations

  • The allowed size and extensions for a given document field can be defined in the form they appear on: when editing a document field, the user has the option to change the maximum size allowed for that file, in any data unit from bytes to petabytes, and also choose from the array of common extensions for given types of documents, for example, .jpeg or .png for images, or even write their own specific array of allowed extensions by selecting the Custom option, and then typing the extensions separated by semicolons (the extensions can be prefixed by a dot: both .png or just png work the same). This means that the same document field can have different configurations if they appear in multiple forms.

Form-Config

Dataunit-options extensions-options-1 extensions-options-custom

Document fields in the MVC webpage

In the generated webpage, the document field will have this appearance:

DocField

To upload a file, the user must click on the 3 dots (...) and select "Attach"

DocField-Attach

After the user selects a file from the file system, the system will check the file size and extension against the configurations defined for that document field. If the file is too large, the webpage will display an error message saying "File is too large", and if the extension is not allowed, the message will read "File type not allowed". If both the size exceed the maximum defined by the user and the extension is not allowed, the system will display the "File type not allowed" message, due to it being the first condition to be checked.

If the file complies to both conditions, it will be uploaded, and after the upload, the document field changes:

docField-uploaded

After the upload, it is possible to download the file by clicking the box where the file name is displayed, and if the user clicks the 3 dots (...), it is also possible to perform the download, edit and delete actions, and additionally view the file properties.

docField-after-uploaded

The edit action downloads the file, and after editing it, it is possible to submit the changed file (or a different one), making it a versioned document, in which it is possible to view, download and delete different versions. The delete action deletes the file that was uploaded, and the document field becomes empty again. The properties display information about the uploaded file:

properties


Conclusion

In this documentation, we have discussed how document fields store files in the database, how to customize their size and allowed extensions, and how they appear and function within an MVC webpage.

By understanding these concepts, you can effectively manage your application's file storage and provide a seamless user experience. We hope this guide has been helpful in enhancing your knowledge of document fields and their customization, and we encourage you to apply these concepts to your projects.