Refactor file URL handling to use relative paths.
Updated file URL generation to return relative paths instead of absolute paths, ensuring better portability and consistency. Adjusted relevant methods to compute paths relative to the base directory.
This commit is contained in:
@@ -79,15 +79,18 @@ class LocalStorageProvider(StorageProvider):
|
||||
# The upload URL is to our custom upload endpoint
|
||||
upload_url = f"{settings.API_VERSION_STR}/uploads/{token}"
|
||||
|
||||
# The file URL is where the file will be accessible after upload
|
||||
file_url = f"{self.upload_folder}/{file_path}"
|
||||
# Return just the relative path
|
||||
upload_folder_relative = os.path.relpath(self.upload_folder, settings.DATA_FILES_DIR)
|
||||
file_url = f"{upload_folder_relative}/{file_path}"
|
||||
|
||||
return upload_url, file_url
|
||||
|
||||
def get_uploaded_file_url(self, file_path: str) -> str:
|
||||
"""Get the URL for accessing a file."""
|
||||
return f"{self.upload_folder}/{file_path}"
|
||||
upload_folder_relative = os.path.relpath(self.upload_folder, settings.DATA_FILES_DIR)
|
||||
return f"{upload_folder_relative}/{file_path}"
|
||||
|
||||
def get_file_url(self, file_path: str) -> str:
|
||||
"""Get the URL for accessing a file."""
|
||||
return f"{self.files_url_path}/{file_path}"
|
||||
# Return just the relative path
|
||||
return file_path
|
||||
Reference in New Issue
Block a user