storage.txt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. .. _ref-files-storage:
  2. File storage API
  3. ================
  4. ``Storage.exists(name)``
  5. ~~~~~~~~~~~~~~~~~~~~~~~~
  6. ``True`` if a file exists given some ``name``.
  7. ``Storage.path(name)``
  8. ~~~~~~~~~~~~~~~~~~~~~~
  9. The local filesystem path where the file can be opened using Python's standard
  10. ``open()``. For storage systems that aren't accessible from the local
  11. filesystem, this will raise ``NotImplementedError`` instead.
  12. ``Storage.size(name)``
  13. ~~~~~~~~~~~~~~~~~~~~~~
  14. Returns the total size, in bytes, of the file referenced by ``name``.
  15. ``Storage.url(name)``
  16. ~~~~~~~~~~~~~~~~~~~~~
  17. Returns the URL where the contents of the file referenced by ``name`` can be
  18. accessed.
  19. ``Storage.open(name, mode='rb')``
  20. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. Opens the file given by ``name``. Note that although the returned file is
  22. guaranteed to be a ``File`` object, it might actually be some subclass. In the
  23. case of remote file storage this means that reading/writing could be quite slow,
  24. so be warned.
  25. ``Storage.save(name, content)``
  26. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. Saves a new file using the storage system, preferably with the name specified.
  28. If there already exists a file with this name ``name``, the storage system may
  29. modify the filename as necessary to get a unique name. The actual name of the
  30. stored file will be returned.
  31. The ``content`` argument must be an instance of
  32. :class:`django.db.files.File` or of a subclass of
  33. :class:`~django.db.files.File`.
  34. ``Storage.delete(name)``
  35. ~~~~~~~~~~~~~~~~~~~~~~~~
  36. Deletes the file referenced by ``name``. This method won't raise an exception if
  37. the file doesn't exist.