Spaces:
Sleeping
Sleeping
File size: 767 Bytes
7da71bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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
|