From a7c256cb5491bf2a77abdff01638239db5bfd9d5 Mon Sep 17 00:00:00 2001 From: Pavel Shpilev Date: Wed, 15 Oct 2014 18:42:06 +1100 Subject: Fixed #9893 -- Allowed using a field's max_length in the Storage. --- docs/ref/files/storage.txt | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'docs/ref/files/storage.txt') diff --git a/docs/ref/files/storage.txt b/docs/ref/files/storage.txt index a16b6b6c9d..88da416dcf 100644 --- a/docs/ref/files/storage.txt +++ b/docs/ref/files/storage.txt @@ -114,12 +114,17 @@ The Storage Class in the storage system, or ``False`` if the name is available for a new file. - .. method:: get_available_name(name) + .. method:: get_available_name(name, max_length=None) Returns a filename based on the ``name`` parameter that's free and available for new content to be written to on the target storage system. + The length of the filename will not exceed ``max_length``, if provided. + If a free unique filename cannot be found, a + :exc:`SuspiciousFileOperation + ` exception will be raised. + If a file with ``name`` already exists, an underscore plus a random 7 character alphanumeric string is appended to the filename before the extension. @@ -133,6 +138,10 @@ The Storage Class attack. This change was also made in Django 1.6.6, 1.5.9, and 1.4.14. + .. versionchanged:: 1.8 + + The ``max_length`` argument was added. + .. method:: get_valid_name(name) Returns a filename based on the ``name`` parameter that's suitable @@ -165,17 +174,24 @@ The Storage Class standard ``open()``. For storage systems that aren't accessible from the local filesystem, this will raise ``NotImplementedError`` instead. - .. method:: save(name, content) + .. method:: save(name, content, max_length=None) Saves a new file using the storage system, preferably with the name specified. If there already exists a file with this name ``name``, the storage system may modify the filename as necessary to get a unique name. The actual name of the stored file will be returned. + The ``max_length`` argument is passed along to + :meth:`get_available_name`. + The ``content`` argument must be an instance of :class:`django.core.files.File` or of a subclass of :class:`~django.core.files.File`. + .. versionchanged:: 1.8 + + The ``max_length`` argument was added. + .. method:: size(name) Returns the total size, in bytes, of the file referenced by ``name``. -- cgit v1.3