def _build_empty_file_query(self, files):
        info = FileCreationInformation()
        info.url = self.file_name
        info.overwrite = True

        qry = create_file_query(files, info)
        self.context.after_execute(self._build_upload_session_query)
        return qry
Exemplo n.º 2
0
    def upload_file(self, name, content):
        """Uploads a file into folder

        :type name: str
        :type content: str
        """
        info = FileCreationInformation()
        info.content = content
        info.url = name
        info.overwrite = True
        target_file = self.files.add(info)
        return target_file
    def create_upload_session(self,
                              source_path,
                              chunk_size,
                              chunk_uploaded=None,
                              *chunk_func_args):
        """Upload a file as multiple chunks

        :param str source_path: path where file to upload resides
        :param int chunk_size: upload chunk size
        :param (long)->None or None chunk_uploaded: uploaded event
        :param chunk_func_args: arguments to pass to chunk_uploaded function
        :return: office365.sharepoint.files.file.File
        """
        file_size = os.path.getsize(source_path)
        if file_size > chunk_size:
            qry = UploadSessionQuery(self, source_path, chunk_size,
                                     chunk_uploaded, chunk_func_args)
            self.context.add_query(qry)
            return qry.file
        else:
            with open(source_path, 'rb') as content_file:
                file_content = content_file.read()
            info = FileCreationInformation(url=os.path.basename(source_path),
                                           overwrite=True,
                                           content=file_content)
            qry = CreateFileQuery(self, info)
            self.context.add_query(qry)
            return qry.return_type
    def upload_file(self, file_name, content):
        """Uploads a file into folder

        :type file_name: str
        :type content: str
        :rtype: office365.sharepoint.files.file.File
        """
        info = FileCreationInformation(url=file_name, overwrite=True, content=content)
        qry = create_file_query(self.files, info)
        self.context.add_query(qry)
        return qry.return_type
def _create_empty_file(path):
    file_name = os.path.basename(path)
    info = FileCreationInformation()
    info.url = file_name
    info.overwrite = True
    return info