2008-08-24 06:25:40 +08:00
|
|
|
File storage API
|
|
|
|
================
|
|
|
|
|
|
|
|
``Storage.exists(name)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
``True`` if a file exists given some ``name``.
|
|
|
|
|
|
|
|
``Storage.path(name)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The local filesystem path where the file can be opened using Python's standard
|
|
|
|
``open()``. For storage systems that aren't accessible from the local
|
|
|
|
filesystem, this will raise ``NotImplementedError`` instead.
|
|
|
|
|
2010-10-08 23:11:59 +08:00
|
|
|
``Storage.accessed_time(name)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. versionadded:: 1.3
|
|
|
|
|
|
|
|
Returns a ``datetime`` object containing the last accessed time of the file.
|
|
|
|
For storage systems that aren't able to return the last accessed time, this
|
|
|
|
will raise ``NotImplementedError`` instead.
|
|
|
|
|
|
|
|
``Storage.created_time(name)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. versionadded:: 1.3
|
|
|
|
|
|
|
|
Returns a ``datetime`` object containing the creation time of the file.
|
|
|
|
For storage systems that aren't able to return the creation time, this
|
|
|
|
will raise ``NotImplementedError`` instead.
|
|
|
|
|
|
|
|
``Storage.modified_time(name)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. versionadded:: 1.3
|
|
|
|
|
|
|
|
Returns a ``datetime`` object containing the last modified time. For storage
|
|
|
|
systems that aren't able to return the last modified time, this will raise
|
|
|
|
``NotImplementedError`` instead.
|
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
``Storage.size(name)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Returns the total size, in bytes, of the file referenced by ``name``.
|
|
|
|
|
|
|
|
``Storage.url(name)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Returns the URL where the contents of the file referenced by ``name`` can be
|
|
|
|
accessed.
|
|
|
|
|
|
|
|
``Storage.open(name, mode='rb')``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Opens the file given by ``name``. Note that although the returned file is
|
|
|
|
guaranteed to be a ``File`` object, it might actually be some subclass. In the
|
|
|
|
case of remote file storage this means that reading/writing could be quite slow,
|
|
|
|
so be warned.
|
|
|
|
|
|
|
|
``Storage.save(name, content)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2008-08-31 18:37:44 +08:00
|
|
|
The ``content`` argument must be an instance of
|
2009-06-10 20:44:53 +08:00
|
|
|
:class:`django.core.files.File` or of a subclass of
|
|
|
|
:class:`~django.core.files.File`.
|
2008-08-31 18:37:44 +08:00
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
``Storage.delete(name)``
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Deletes the file referenced by ``name``. This method won't raise an exception if
|
|
|
|
the file doesn't exist.
|
|
|
|
|