Coretex
coretex.networking.chunk_upload_session.ChunkUploadSession Class Reference

Public Member Functions

str run (self)
 

Detailed Description

    A class which splits a file into chunks and uploades it
    chunk by chunk. This class should be used for uploading
    files larger than 2 GiB, since Python does not support
    uploading files with a larger size.

    Maximum chunk size is 128 MiB.

    Properties
    ----------
    chunkSize : int
        size of chunks into which the file will be split
        maximum value is 128 MiB, while the minimum value is 1
    filePath : Union[Path, str]
        path to the file which will be uploaded
    fileSize : int
        size of the file which will be uploaded
    mimeType : str
        mime type of the file - if None is passed, guess will
        be performed, if guess fails Exception will be raised

Definition at line 38 of file chunk_upload_session.py.

Member Function Documentation

◆ run()

str coretex.networking.chunk_upload_session.ChunkUploadSession.run (   self)
    Uploads the file to Coretex.ai

    Returns
    -------
    str -> ID of the uploaded file

    Raises
    ------
    NetworkRequestError, ValueError -> if some kind of error happened during
    the upload of the provided file

    Example
    -------
    >>> from coretex.networking import ChunkUploadSession, NetworkRequestError
    \b
    >>> chunkSize = 16 * 1024 * 1024  # chunk size: 16 MiB
    >>> uploadSession = ChunkUploadSession(chunkSize, path/fo/file.ext)
    \b
    >>> try:
    uploadId = uploadSession.run()
    print(uploadId)
except NetworkRequestError, ValueError:
    print("Failed to upload file")

Definition at line 111 of file chunk_upload_session.py.

111  def run(self) -> str:
112  """
113  Uploads the file to Coretex.ai
114 
115  Returns
116  -------
117  str -> ID of the uploaded file
118 
119  Raises
120  ------
121  NetworkRequestError, ValueError -> if some kind of error happened during
122  the upload of the provided file
123 
124  Example
125  -------
126  >>> from coretex.networking import ChunkUploadSession, NetworkRequestError
127  \b
128  >>> chunkSize = 16 * 1024 * 1024 # chunk size: 16 MiB
129  >>> uploadSession = ChunkUploadSession(chunkSize, path/fo/file.ext)
130  \b
131  >>> try:
132  uploadId = uploadSession.run()
133  print(uploadId)
134  except NetworkRequestError, ValueError:
135  print("Failed to upload file")
136  """
137  logging.getLogger("coretexpylib").info(f">> [Coretex] Starting upload for \"{self.filePath}\"")
138 
139  uploadId = self.__start()
140 
141  chunkCount = self.fileSize // self.chunkSize
142  if self.fileSize % self.chunkSize != 0:
143  chunkCount += 1
144 
145  for i in range(chunkCount):
146  start = i * self.chunkSize
147  end = min(start + self.chunkSize, self.fileSize)
148 
149  self.__uploadChunk(uploadId, start, end)
150 
151  return uploadId

The documentation for this class was generated from the following file: