Exemplo n.º 1
0
    def _upload(self, oid, file_like, metadata=None) -> OInfo:
        res = None
        metadata = metadata or {}

        file_like.seek(0, io.SEEK_END)
        size = file_like.tell()
        file_like.seek(0)

        if size < self.large_file_size:
            res = self._api('files_upload',
                            file_like.read(),
                            oid,
                            mode=files.WriteMode('overwrite'))
        else:
            cursor = None

            while True:
                data = file_like.read(self.upload_block_size)
                if not data:
                    if cursor:
                        local_mtime = arrow.get(
                            metadata.get('mtime', time.time())).datetime
                        commit = files.CommitInfo(
                            path=oid,
                            mode=files.WriteMode.overwrite,
                            autorename=False,
                            client_modified=local_mtime,
                            mute=True)
                        res = self._api('files_upload_session_finish', data,
                                        cursor, commit)
                    break
                if not cursor:
                    res = self._api('files_upload_session_start', data)
                    cursor = files.UploadSessionCursor(res.session_id,
                                                       len(data))
                else:
                    self._api('files_upload_session_append_v2', data, cursor)
                    cursor.offset += len(data)

        if res is None:
            raise CloudFileExistsError()

        ret = OInfo(otype=FILE,
                    oid=res.id,
                    hash=res.content_hash,
                    path=res.path_display,
                    size=size,
                    mtime=self._mtime_from_metadata(res))
        log.debug('upload result is %s', ret)
        return ret
Exemplo n.º 2
0
 def upload_files(self):
     filer = Filer()
     for p in config.PATHS:
         # get url to zip file
         zipfile = filer.archive_file(p)
         dropfile = '/' + config.DROP_BOX_FOLDER + '/' + path.normpath(
             path.basename(zipfile))
         # upload file to dropbox
         with open(zipfile, 'rb') as f:
             self.db.files_upload(f.read(),
                                  dropfile,
                                  mode=files.WriteMode('overwrite'))
             # delete file after upload
             filer.delete_file(zipfile)
Exemplo n.º 3
0
    def upload_file(self, trigger_data):
        try:
            if self.data_obj['path'] is not None:
                upload_path = self.data_obj['path'] + '/' + self.data_obj[
                    'filename']
            else:
                upload_path = '/' + self.data_obj['filename']

            self.dropbox_obj.files_upload(trigger_data['upload_data'],
                                          upload_path,
                                          mode=files.WriteMode('overwrite'))
            apps_logger.info("Dropbox:UploadAction:ActionSuccessful - ZapID=" +
                             str(self.data_obj['zap_id']))

        except Exception as e:
            apps_error_logger.info("DropboxError:UploadAction:ActionFailed:" +
                                   str(e))
    def upload_file(self,
                    file_bytes: bytes,
                    upload_path: str,
                    write_mode: str = 'overwrite') -> None:
        """
        Uploads a file to the Cloudstore

        :param file_bytes:
        :param upload_path:
        :param write_mode:
        :return:
        """

        # TODO: Add option to support FileStream, StringIO and FilePath
        try:
            logger.debug("Uploading file to path: %s" % upload_path)
            self._handler.files_upload(f=file_bytes,
                                       path=upload_path,
                                       mode=files.WriteMode(write_mode))
        except exceptions.ApiError as err:
            logger.error('API error: %s' % err)
Exemplo n.º 5
0
    def upload_file(self,
                    file_bytes: bytes,
                    upload_path: str,
                    write_mode: str = 'overwrite') -> None:
        """
        Uploads a file to the Cloudstore

        :param file_bytes:
        :param upload_path:
        :param write_mode:
        :return:
        """

        upload_path = self.remote_folder + upload_path

        try:
            logger.debug("Uploading file to path: %s" % upload_path)
            self._handler.files_upload(f=file_bytes,
                                       path=upload_path,
                                       mode=files.WriteMode(write_mode))
        except exceptions.ApiError as err:
            logger.error('API error: %s' % err)