From 16bd54b8d350126c81eb47e2c0d7f1ebc100fa1c Mon Sep 17 00:00:00 2001 From: Dave Mateer Date: Tue, 12 Jul 2022 12:44:29 +0100 Subject: [PATCH] Put in fix for leading / in Google Drive --- storages/gd_storage.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/storages/gd_storage.py b/storages/gd_storage.py index e772a90..2a92f51 100644 --- a/storages/gd_storage.py +++ b/storages/gd_storage.py @@ -28,6 +28,12 @@ class GDStorage(Storage): only support files saved in a folder for GD S3 supports folder and all stored in the root """ + # doesn't work if key starts with / which can happen from telethon + if key.startswith('/'): + # remove first character ie / + logger.debug(f'CDN: Found and fixing leading / on uploading a file with {key=}') + key = key[1:] + full_name = os.path.join(self.folder, key) parent_id, folder_id = self.root_folder_id, None path_parts = full_name.split(os.path.sep) @@ -52,6 +58,13 @@ class GDStorage(Storage): 1. for each sub-folder in the path check if exists or create 2. upload file to root_id/other_paths.../filename """ + # doesn't work if key starts with / which can happen from telethon + if key.startswith('/'): + # remove first character ie / + logger.debug(f'UPLOADF: Found and fixing a leading / on uploading a file with {key=}') + key = key[1:] + + full_name = os.path.join(self.folder, key) parent_id, upload_to = self.root_folder_id, None path_parts = full_name.split(os.path.sep)