Fixed bug in local file storage URL generation.

This commit is contained in:
2017-03-22 16:05:38 +01:00
parent cce388049d
commit 6b526f6b53
3 changed files with 38 additions and 3 deletions

View File

@@ -11,7 +11,8 @@ __all__ = ['Bucket', 'Blob', 'Path', 'FileType']
# Shorthand for the type of path we use.
Path = pathlib.PurePosixPath
# This is a mess: typing.IO keeps mypy-0.501 happy, and io.FileIO keeps PyCharm-2017.1 happy.
# This is a mess: typing.IO keeps mypy-0.501 happy, but not in all cases,
# and io.FileIO keeps PyCharm-2017.1 happy.
FileType = typing.Union[typing.IO, io.FileIO]

View File

@@ -22,7 +22,8 @@ class LocalBucket(Bucket):
# For local storage, the name is actually a partial path, relative
# to the local storage root.
self.root = pathlib.Path(current_app.config['STORAGE_DIR'])
self.abspath = self.root / name[:2] / name
self.bucket_path = pathlib.PurePosixPath(name[:2]) / name
self.abspath = self.root / self.bucket_path
def blob(self, blob_name: str) -> 'LocalBlob':
return LocalBlob(name=blob_name, bucket=self)
@@ -71,7 +72,8 @@ class LocalBlob(Blob):
def get_url(self, *, is_public: bool) -> str:
from flask import url_for
url = url_for('file_storage.index', file_name=str(self.partial_path), _external=True,
path = self.bucket.bucket_path / self.partial_path
url = url_for('file_storage.index', file_name=str(path), _external=True,
_scheme=current_app.config['SCHEME'])
return url