mirror of
https://github.com/wassname/flask-cloudy.git
synced 2026-09-09 11:22:27 +08:00
0.12.0 - Fixed prefix in Storage.upload that assumed prefix is a directory
This commit is contained in:
+13
-1
@@ -29,4 +29,16 @@ docs/_build*
|
||||
|
||||
.test_config
|
||||
|
||||
.tox
|
||||
.tox
|
||||
|
||||
tests/*
|
||||
!tests/__init__.py
|
||||
!tests/config.py
|
||||
!tests/test_cloudy.py
|
||||
|
||||
tests/data/*
|
||||
!tests/data/hello.txt
|
||||
!tests/data/hello.js
|
||||
|
||||
tests/container_1/*
|
||||
!tests/container_1/empty
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
0.12.0
|
||||
- Fixed prefix in Storage.upload that assumed the prefix is a directory
|
||||
Add a slash / at the end of prefix to make it a directory, or it will
|
||||
just append it to the name
|
||||
|
||||
0.11.0
|
||||
- Removed flask_cloudy.Object.short_url now use flask_cloudy.Object.url
|
||||
- Added flask_cloudy.Object.full_url to have the domain for local storage
|
||||
|
||||
@@ -298,7 +298,8 @@ To save or upload a file in the container
|
||||
|
||||
- name: to give the file a new name
|
||||
|
||||
- prefix: a name to add in front of the file name. It can make it a directory
|
||||
- prefix: a name to add in front of the file name. Add a slash at the end of
|
||||
prefix to make it a directory otherwise it will just append it to the name
|
||||
|
||||
- allowed_extensions: list of extensions
|
||||
|
||||
@@ -324,20 +325,29 @@ To save or upload a file in the container
|
||||
The uploaded file will be named: **new_readme.md**
|
||||
|
||||
|
||||
**3) Put the uploaded file under a different location**
|
||||
**3) Put the uploaded file under a different location using `prefix`**
|
||||
|
||||
|
||||
storage.upload(my_file, name="new_readme", prefix="my_dir/")
|
||||
|
||||
|
||||
now the filename becomes **my_dir/new_readme.md**
|
||||
|
||||
On LOCAL it will create the directory *my_dir* if it doesn't exist.
|
||||
|
||||
|
||||
**4a.) Public upload **
|
||||
storage.upload(my_file, name="new_readme", prefix="my_new_path-")
|
||||
|
||||
|
||||
now the filename becomes **my_new_path-new_readme.md**
|
||||
|
||||
|
||||
**4a.) Public upload**
|
||||
|
||||
storage.upload(my_file, public=True)
|
||||
|
||||
**4b.) Private upload **
|
||||
|
||||
**4b.) Private upload**
|
||||
|
||||
storage.upload(my_file, public=False)
|
||||
|
||||
|
||||
+1
-1
@@ -297,7 +297,7 @@ class Storage(object):
|
||||
name = secure_filename(name)
|
||||
|
||||
if prefix:
|
||||
name = prefix.strip("/") + "/" + name
|
||||
name = prefix.lstrip("/") + name
|
||||
|
||||
if not overwrite:
|
||||
name = self._safe_object_name(name)
|
||||
|
||||
@@ -19,7 +19,7 @@ Supported storage:
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
__NAME__ = "Flask-Cloudy"
|
||||
__version__ = "0.11.0"
|
||||
__version__ = "0.12.0"
|
||||
__author__ = "Mardix"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "2015"
|
||||
|
||||
@@ -149,8 +149,8 @@ def test_storage_upload_append_extension():
|
||||
def test_storage_upload_with_prefix():
|
||||
storage = app_storage()
|
||||
object_name = "my-txt-hello-hello"
|
||||
prefix = "dir1/dir2/dir3"
|
||||
full_name = "%s/%s.%s" % (prefix, object_name, "txt")
|
||||
prefix = "dir1/dir2/dir3/"
|
||||
full_name = "%s%s.%s" % (prefix, object_name, "txt")
|
||||
o = storage.upload(CWD + "/data/hello.txt", name=object_name, prefix=prefix, overwrite=True)
|
||||
assert full_name in storage
|
||||
assert o.name == full_name
|
||||
@@ -160,7 +160,7 @@ def test_save_to():
|
||||
storage = app_storage()
|
||||
object_name = "my-txt-hello-to-save.txt"
|
||||
o = storage.upload(CWD + "/data/hello.txt", name=object_name)
|
||||
file = o.save_to("./data", overwrite=True)
|
||||
file = o.save_to(CWD + "/data", overwrite=True)
|
||||
file2 = o.save_to(CWD + "/data", name="my_new_file", overwrite=True)
|
||||
assert os.path.isfile(file)
|
||||
assert file2 == CWD + "/data/my_new_file.txt"
|
||||
|
||||
Reference in New Issue
Block a user