Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| import logging | |
| import dropbox | |
| from dropbox.files import WriteMode | |
| logger = logging.getLogger(__name__) | |
| class DropboxClient: | |
| def __init__(self, app_key: str, app_secret: str, refresh_token: str) -> None: | |
| self._dbx = dropbox.Dropbox( | |
| app_key=app_key, | |
| app_secret=app_secret, | |
| oauth2_refresh_token=refresh_token, | |
| ) | |
| def upload(self, file_bytes: bytes, dest_path: str) -> str: | |
| """Upload bytes to dest_path. Returns the path Dropbox assigned (may differ on collision).""" | |
| result = self._dbx.files_upload( | |
| file_bytes, | |
| dest_path, | |
| mode=WriteMode.add, | |
| autorename=True, | |
| ) | |
| return result.path_display | |