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.
Methods
create_file
(file[, folder, filename, expiration])Create a new file on the server by uploading a local file.
delete
(*args, **kwargs)Send a DELETE request.
delete_file
(item)Delete a file instance.
get
(*args, **kwargs)Send a GET request.
get_file
(item[, refresh])Return a file instance.
get_file_content
(file)Download the contents of a file.
get_link
(obj, rel)Get link information from a resource.
head
(*args, **kwargs)Send a HEAD request.
info
()Version and build information for the service.
is_available
()Check if the service is currently available.
list_files
([filter, start, limit])List all files available in the environment.
post
(*args, **kwargs)Send a POST request.
put
(*args, **kwargs)Send a PUT request.
request
(verb, path[, session, format_])Send an HTTP request with a session.
request_link
(obj, rel, **kwargs)Request a link from a resource.
update_file
(item)Update a file instance.
is_uuid
- classmethod create_file(file, folder=None, filename=None, expiration=None)[source]#
Create a new file on the server by uploading a local file.
- Parameters:
- filestr or file_like
Path to the file to upload or a file-like object.
- folderstr or dict, optional
Name, or, or folder information as returned by
get_folder()
.- filenamestr, optional
Name to assign to the uploaded file. Defaults to the filename if file is a path, otherwise required.
- expirationdatetime, 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:
- itemstr or dict
Name, ID, or dictionary representation of the file.
- refreshbool, 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:
- filestr or dict, optional
Name or file information as returned by
get_file()
.
- Returns:
- content
- classmethod list_files(filter=None, start=None, limit=None, **kwargs)#
List all files available in the environment.
- Parameters:
- filterstr, optional
- startint, optional
Zero-based index of the first item to return. Defaults to 0.
- limitint, 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:
- itemdict
- Returns:
- None