From 9cc36571e06e08904dd60c28b9d88d758463e0d5 Mon Sep 17 00:00:00 2001 From: mutantsan Date: Thu, 26 May 2022 15:45:01 +0300 Subject: [PATCH] add get_url_by_path method --- ckanext/cloudstorage/storage.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ckanext/cloudstorage/storage.py b/ckanext/cloudstorage/storage.py index edf254e..f5881f7 100644 --- a/ckanext/cloudstorage/storage.py +++ b/ckanext/cloudstorage/storage.py @@ -376,24 +376,24 @@ def upload(self, id, max_size=10): return def get_url_from_filename(self, rid, filename, content_type=None): + path = self.path_from_filename(rid, filename) + + return self.get_url_by_path(path, content_type) + + def get_url_by_path(self, path, content_type=None): """ - Retrieve a publically accessible URL for the given resource_id - and filename. + Retrieve a publically accessible URL for the given path .. note:: Works for Azure and any libcloud driver that implements support for get_object_cdn_url (ex: AWS S3). - :param rid: The resource ID. - :param filename: The resource filename. + :param path: The resource name on cloud. :param content_type: Optionally a Content-Type header. :returns: Externally accessible URL or None. """ - # Find the key the file *should* be stored at. - path = self.path_from_filename(rid, filename) - # If advanced azure features are enabled, generate a temporary # shared access link instead of simply redirecting to the file. if self.can_use_advanced_azure and self.use_secure_urls: