sasctl.services.files#

class sasctl._services.files.Files[source]#

Bases: Service

The Files API provides persistence and retrieval of files, such as documents, attachments, and reports.

The file can be associated with the URI of another identifiable object (for example, a parentUri). Every file must have an assigned content type and name. Files can be retrieved individually by using the file’s identifier or as a list of files by using a parentUri. Each file has its content stream associated with it. After creation, the metadata that is associated with the file or the actual content can be updated. A single file can be deleted by using a specific ID. Multiple files can be deleted by specifying a parentUri. A file can be uploaded via raw request or multipart form request.

classmethod create_file(file, folder=None, filename=None, expiration=None)[source]#

Create a new file on the server by uploading a local file.

Parameters:
  • file (str, pathlib.Path, or BinaryIO) – Path to the file to upload or a file-like object.

  • folder (str or dict, optional) – Name or folder information as returned by get_folder().

  • filename (str, optional) – Name to assign to the uploaded file. Defaults to the filename if file is a path, otherwise required.

  • expiration (datetime.datetime, optional) – A timestamp that indicates when to expire the file. Defaults to no expiration.

Returns:

RestObj – A dictionary containing the file attributes.

classmethod delete_file(item)#

Delete a file instance.

Parameters:

item

Returns:

None

classmethod get_file(item, refresh=False)#

Return a file instance.

Parameters:
  • item (str or dict) – Name, ID, or dictionary representation of the file.

  • refresh (bool, optional) – Obtain an updated copy of the file.

Returns:

RestObj or None – A dictionary containing the file attributes or None.

Notes

If item is a complete representation of the file it will be returned unless refresh is set. This prevents unnecessary REST calls when data is already available on the client.

classmethod get_file_content(file)[source]#

Download the contents of a file.

Parameters:

file (str or dict, optional) – Name or file information as returned by get_file().

Returns:

str – content

classmethod list_files(filter=None, start=None, limit=None, **kwargs)#

List all files available in the environment.

Parameters:
  • filter (str, optional)

  • start (int, optional) – Zero-based index of the first item to return. Defaults to 0.

  • limit (int, optional) – The maximum number of items to return. Defaults to 20.

Returns:

list – A list of dictionaries containing the files.

Notes

See the filtering reference for details on the filter parameter.

classmethod update_file(item)#

Update a file instance.

Parameters:

item (dict)

Returns:

None