code: def upload(self, filepath, filename=None):
          
          if not filename:
              filename = os.path.basename(filepath)
  
          content_upload = self.create()
  
          try:
              offset = 0
              content_chunk_size = 2 * 1024 * 1024
  
              with open(filepath, 'rb') as contentfile:
                  chunk = contentfile.read(content_chunk_size)
                  while len(chunk) > 0:
                      data = {'offset': offset,
                              'content': chunk}
                      content_upload.update(data)
  
                      offset += len(chunk)
                      chunk = contentfile.read(content_chunk_size)
  
              size = 0
              checksum = hashlib.sha256()
              with open(filepath, 'rb') as contentfile:
                  contents = contentfile.read()
                  size = len(contents)
                  checksum.update(contents)
  
              uploads = [{'id': content_upload.upload_id, 'name': filename,
                          'size': size, 'checksum': checksum.hexdigest()}]
              # pylint:disable=no-member
              json = self.repository.import_uploads(uploads)
          finally:
              content_upload.delete()
  
          return json
docs: Upload content.
  
          :param filepath: path to the file that should be chunked and uploaded
          :param filename: name of the file on the server, defaults to the
              last part of the ``filepath`` if not set
          :returns: The server's response, with all JSON decoded.
          :raises: ``requests.exceptions.HTTPError`` If the server responds with
              an HTTP 4XX or 5XX message.
          :raises nailgun.entities.APIResponseError: If the response has a status
              other than "success".
  
          .. _POST a Multipart-Encoded File:
              http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
          .. _POST Multiple Multipart-Encoded Files:
              http://docs.python-requests.org/en/latest/user/advanced/#post-multiple-multipart-encoded-files