diff --git a/middleware/app_be/services/dropboxservice.py b/middleware/app_be/services/dropboxservice.py index b0fca3e..cd5199d 100644 --- a/middleware/app_be/services/dropboxservice.py +++ b/middleware/app_be/services/dropboxservice.py @@ -6,7 +6,6 @@ from app_be.services.StorageServiceInterface import StorageServiceInterface class DropboxService(StorageServiceInterface): - name = "Dropbox" @staticmethod @@ -57,13 +56,24 @@ class DropboxService(StorageServiceInterface): @staticmethod def update_file(filename: str, file: bytes) -> bool: - """Update (currently: overwrite) an file on the dropbox storage. + """Update a file on the dropbox storage. + Increments a counter until we get to the newest version, then + create the file with the newest version + 1. :param filename: filename of the file :param file: bytes representation of the file :return: Whether file was successfully uploaded """ - return DropboxService.create_file(filename, file) + i = 0 + while True: + try: + dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_ACCESS_TOKEN) + dbx.files_get_metadata(filename + '_' + str(i)) + i = i + 1 + except: + break + + return DropboxService.create_file(filename + '_' + str(i), file) @staticmethod def delete_file(filename: str) -> bool: