File¶
A file is a collection of data stored in one unit, identified by a filename. It can be a document, picture, data library, binary data, or any other collection of data.
In order to work with the File entity we will be using the following import throughout the examples:
Below we have all the required attributes associated with the File Entity
-
name: The name of the File entity -
tags: The tags of the file. -
description: The current description of the file. -
workspace: Which workspace will the File entity reside. -
date: The date of the file. -
data: The data of the file in base64 format. -
content_type: Refers to the media type of the file. -
url: The URL which the file will reside.
Creating a File Entity¶
For creating a brand new File entity we can simply instantiate the class and passing our desired arguments:
file = File()
file.name = 'SampleFile'
file.tags = ['tag1', 'tag2']
file.description = 'Description'
file.workspace = 'SampleWorkspace'
file.date = '20230909'
file.data = 'data'
file.content_type = 'text/plain'
file.url = '/filehttps://example.com'
Convert File Entity to Dictionary¶
For converting a File entity to a python dictionary, we can make use of the to_dict() method, let's see that in practice by using our previously created File entity:
file = File()
type(file)
everysk.sdk.entities.file.base.File
to_dict = file.to_dict(file)
type(to_dict)
# dict
Validate the File Entity¶
The validate() method from the File entity is used as a lazy validation method in order to check if the entity is valid or not by returning a boolean value:
In the case of an invalid entity, the validate() method will raise a FieldValueError in the case of an invalid entity or a RequiredFieldError in the case of a missing required field.