Source code for


The following methods allow for interaction into the
:devportal:`file <file>` API endpoints.

Methods available on ``tio.files``:

.. rst-class:: hide-signature
.. autoclass:: FileAPI

    .. automethod:: upload
from .base import TIOEndpoint
import uuid

[docs]class FileAPI(TIOEndpoint):
[docs] def upload(self, fobj, encrypted=False): ''' Uploads a file into :devportal:`file: upload <file-upload>` Args: fobj (FileObject): The file object intended to be uploaded into encrypted (bool, optional): If the file is encrypted, set the flag to True. Returns: :obj:`str`: The fileuploaded attribute Examples: >>> with open('file.txt') as fobj: ... file_id = tio.files.upload(fobj) ''' # We will attempt to discover the name of the file stored within the # file object. If none exists however, we will generate a random # uuid string to use instead. kw = dict() if encrypted: kw['data'] = {'no_enc': int(encrypted)} kw['files'] = {'Filedata': fobj} return'file/upload', **kw).json()['fileuploaded']