<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>File storage API — Django v1.2 documentation</title> <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../../', VERSION: '1.2', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../../_static/jquery.js"></script> <script type="text/javascript" src="../../_static/underscore.js"></script> <script type="text/javascript" src="../../_static/doctools.js"></script> <link rel="top" title="Django v1.2 documentation" href="../../index.html" /> <link rel="up" title="File handling" href="index.html" /> <link rel="next" title="Forms" href="../forms/index.html" /> <link rel="prev" title="The File object" href="file.html" /> <script type="text/javascript" src="../../templatebuiltins.js"></script> <script type="text/javascript"> (function($) { if (!django_template_builtins) { // templatebuiltins.js missing, do nothing. return; } $(document).ready(function() { // Hyperlink Django template tags and filters var base = "../templates/builtins.html"; if (base == "#") { // Special case for builtins.html itself base = ""; } // Tags are keywords, class '.k' $("div.highlight\\-html\\+django span.k").each(function(i, elem) { var tagname = $(elem).text(); if ($.inArray(tagname, django_template_builtins.ttags) != -1) { var fragment = tagname.replace(/_/, '-'); $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>"); } }); // Filters are functions, class '.nf' $("div.highlight\\-html\\+django span.nf").each(function(i, elem) { var filtername = $(elem).text(); if ($.inArray(filtername, django_template_builtins.tfilters) != -1) { var fragment = filtername.replace(/_/, '-'); $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>"); } }); }); })(jQuery); </script> </head> <body> <div class="document"> <div id="custom-doc" class="yui-t6"> <div id="hd"> <h1><a href="../../index.html">Django v1.2 documentation</a></h1> <div id="global-nav"> <a title="Home page" href="../../index.html">Home</a> | <a title="Table of contents" href="../../contents.html">Table of contents</a> | <a title="Global index" href="../../genindex.html">Index</a> | <a title="Module index" href="../../py-modindex.html">Modules</a> </div> <div class="nav"> « <a href="file.html" title="The <tt class="docutils literal docutils literal docutils literal"><span class="pre">File</span></tt> object">previous</a> | <a href="../index.html" title="API Reference" accesskey="U">up</a> | <a href="../forms/index.html" title="Forms">next</a> »</div> </div> <div id="bd"> <div id="yui-main"> <div class="yui-b"> <div class="yui-g" id="ref-files-storage"> <div class="section" id="s-file-storage-api"> <span id="file-storage-api"></span><h1>File storage API<a class="headerlink" href="#file-storage-api" title="Permalink to this headline">¶</a></h1> <div class="section" id="s-storage-exists-name"> <span id="storage-exists-name"></span><h2><tt class="docutils literal"><span class="pre">Storage.exists(name)</span></tt><a class="headerlink" href="#storage-exists-name" title="Permalink to this headline">¶</a></h2> <p><tt class="xref docutils literal"><span class="pre">True</span></tt> if a file exists given some <tt class="docutils literal"><span class="pre">name</span></tt>.</p> </div> <div class="section" id="s-storage-path-name"> <span id="storage-path-name"></span><h2><tt class="docutils literal"><span class="pre">Storage.path(name)</span></tt><a class="headerlink" href="#storage-path-name" title="Permalink to this headline">¶</a></h2> <p>The local filesystem path where the file can be opened using Python’s standard <tt class="docutils literal"><span class="pre">open()</span></tt>. For storage systems that aren’t accessible from the local filesystem, this will raise <tt class="docutils literal"><span class="pre">NotImplementedError</span></tt> instead.</p> </div> <div class="section" id="s-storage-size-name"> <span id="storage-size-name"></span><h2><tt class="docutils literal"><span class="pre">Storage.size(name)</span></tt><a class="headerlink" href="#storage-size-name" title="Permalink to this headline">¶</a></h2> <p>Returns the total size, in bytes, of the file referenced by <tt class="docutils literal"><span class="pre">name</span></tt>.</p> </div> <div class="section" id="s-storage-url-name"> <span id="storage-url-name"></span><h2><tt class="docutils literal"><span class="pre">Storage.url(name)</span></tt><a class="headerlink" href="#storage-url-name" title="Permalink to this headline">¶</a></h2> <p>Returns the URL where the contents of the file referenced by <tt class="docutils literal"><span class="pre">name</span></tt> can be accessed.</p> </div> <div class="section" id="s-storage-open-name-mode-rb"> <span id="storage-open-name-mode-rb"></span><h2><tt class="docutils literal"><span class="pre">Storage.open(name,</span> <span class="pre">mode='rb')</span></tt><a class="headerlink" href="#storage-open-name-mode-rb" title="Permalink to this headline">¶</a></h2> <p>Opens the file given by <tt class="docutils literal"><span class="pre">name</span></tt>. Note that although the returned file is guaranteed to be a <tt class="docutils literal"><span class="pre">File</span></tt> 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.</p> </div> <div class="section" id="s-storage-save-name-content"> <span id="storage-save-name-content"></span><h2><tt class="docutils literal"><span class="pre">Storage.save(name,</span> <span class="pre">content)</span></tt><a class="headerlink" href="#storage-save-name-content" title="Permalink to this headline">¶</a></h2> <p>Saves a new file using the storage system, preferably with the name specified. If there already exists a file with this name <tt class="docutils literal"><span class="pre">name</span></tt>, the storage system may modify the filename as necessary to get a unique name. The actual name of the stored file will be returned.</p> <p>The <tt class="docutils literal"><span class="pre">content</span></tt> argument must be an instance of <a class="reference internal" href="file.html#django.core.files.File" title="django.core.files.File"><tt class="xref py py-class docutils literal"><span class="pre">django.core.files.File</span></tt></a> or of a subclass of <a class="reference internal" href="file.html#django.core.files.File" title="django.core.files.File"><tt class="xref py py-class docutils literal"><span class="pre">File</span></tt></a>.</p> </div> <div class="section" id="s-storage-delete-name"> <span id="storage-delete-name"></span><h2><tt class="docutils literal"><span class="pre">Storage.delete(name)</span></tt><a class="headerlink" href="#storage-delete-name" title="Permalink to this headline">¶</a></h2> <p>Deletes the file referenced by <tt class="docutils literal"><span class="pre">name</span></tt>. This method won’t raise an exception if the file doesn’t exist.</p> </div> </div> </div> </div> </div> <div class="yui-b" id="sidebar"> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">File storage API</a><ul> <li><a class="reference internal" href="#storage-exists-name"><tt class="docutils literal"><span class="pre">Storage.exists(name)</span></tt></a></li> <li><a class="reference internal" href="#storage-path-name"><tt class="docutils literal"><span class="pre">Storage.path(name)</span></tt></a></li> <li><a class="reference internal" href="#storage-size-name"><tt class="docutils literal"><span class="pre">Storage.size(name)</span></tt></a></li> <li><a class="reference internal" href="#storage-url-name"><tt class="docutils literal"><span class="pre">Storage.url(name)</span></tt></a></li> <li><a class="reference internal" href="#storage-open-name-mode-rb"><tt class="docutils literal"><span class="pre">Storage.open(name,</span> <span class="pre">mode='rb')</span></tt></a></li> <li><a class="reference internal" href="#storage-save-name-content"><tt class="docutils literal"><span class="pre">Storage.save(name,</span> <span class="pre">content)</span></tt></a></li> <li><a class="reference internal" href="#storage-delete-name"><tt class="docutils literal"><span class="pre">Storage.delete(name)</span></tt></a></li> </ul> </li> </ul> <h3>Browse</h3> <ul> <li>Prev: <a href="file.html">The <tt class="docutils literal docutils literal docutils literal"><span class="pre">File</span></tt> object</a></li> <li>Next: <a href="../forms/index.html">Forms</a></li> </ul> <h3>You are here:</h3> <ul> <li> <a href="../../index.html">Django v1.2 documentation</a> <ul><li><a href="../index.html">API Reference</a> <ul><li><a href="index.html">File handling</a> <ul><li>File storage API</li></ul> </li></ul></li></ul> </li> </ul> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../../_sources/ref/files/storage.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../../search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <h3>Last update:</h3> <p class="topless">Oct 20, 2010</p> </div> </div> <div id="ft"> <div class="nav"> « <a href="file.html" title="The <tt class="docutils literal docutils literal docutils literal"><span class="pre">File</span></tt> object">previous</a> | <a href="../index.html" title="API Reference" accesskey="U">up</a> | <a href="../forms/index.html" title="Forms">next</a> »</div> </div> </div> <div class="clearer"></div> </div> </body> </html>