{"title":"An réad ``Comhad ``","version":"6.0","locale":"ga","docname":"ref/files/file","url":"/ga/6.0/ref/files/file/","canonical":"https://djangodocs.dev/ga/6.0/ref/files/file/","summary":"Tá ranganna ionsuite sa mhodúl:MOD: django.core.files agus a fho-mhodúil le haghaidh láimhseáil comhaid bunúsach i Django.","html":"<h1>An réad <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">``</span></a>Comhad ``<a class=\"heading-anchor\" href=\"#the-file-object\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Tá ranganna ionsuite sa mhodúl:MOD: django.core.files agus a fho-mhodúil le haghaidh láimhseáil comhaid bunúsach i Django.</p>\n<section id=\"the-file-class\">\n<h2>An rang <code class=\"docutils literal notranslate\">Comhad ``</code><a class=\"heading-anchor\" href=\"#the-file-class\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">File</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">file_object</em>, <em class=\"sig-param\">name<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.File\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The <a class=\"reference internal\" href=\"#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> class is a thin wrapper around a Python\n<a class=\"reference external\" href=\"https://docs.python.org/3/glossary.html#term-file-object\" title=\"(in Python v3.14)\"><span class=\"xref std std-term\">file object</span></a> with some Django-specific additions.\nInternally, Django uses this class when it needs to represent a file.</p>\n<p><a class=\"reference internal\" href=\"#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> objects have the following attributes and methods:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.name\">\n<span class=\"sig-name descname\">name</span><a class=\"heading-anchor\" href=\"#django.core.files.File.name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Ainm an chomhaid lena n-áirítear an cosán coibhneasta ó:setting: MEDIA_ROOT.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.size\">\n<span class=\"sig-name descname\">size</span><a class=\"heading-anchor\" href=\"#django.core.files.File.size\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Méid an chomhaid i mbetaí.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.file\">\n<span class=\"sig-name descname\">file</span><a class=\"heading-anchor\" href=\"#django.core.files.File.file\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The underlying <a class=\"reference external\" href=\"https://docs.python.org/3/glossary.html#term-file-object\" title=\"(in Python v3.14)\"><span class=\"xref std std-term\">file object</span></a> that this class wraps.</p>\n<aside class=\"admonition-be-careful-with-this-attribute-in-subclasses admonition\" role=\"note\">\n<p class=\"admonition-title\">Bí cúramach leis an tréith seo i bhfo-aicmí.</p>\n<p>Some subclasses of <a class=\"reference internal\" href=\"#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a>, including\n<a class=\"reference internal\" href=\"#django.core.files.base.ContentFile\" title=\"django.core.files.base.ContentFile\"><code class=\"xref py py-class docutils literal notranslate\">ContentFile</code></a> and\n<a class=\"reference internal\" href=\"/ga/6.0/ref/models/fields/#django.db.models.fields.files.FieldFile\" title=\"django.db.models.fields.files.FieldFile\"><code class=\"xref py py-class docutils literal notranslate\">FieldFile</code></a>, may replace this\nattribute with an object other than a Python <a class=\"reference external\" href=\"https://docs.python.org/3/glossary.html#term-file-object\" title=\"(in Python v3.14)\"><span class=\"xref std std-term\">file\nobject</span></a>. In these cases, this attribute may itself be a\n<a class=\"reference internal\" href=\"#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> subclass (and not necessarily the same subclass).\nWhenever possible, use the attributes and methods of the subclass\nitself rather than those of the subclass's <code class=\"docutils literal notranslate\">file</code> attribute.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.mode\">\n<span class=\"sig-name descname\">mode</span><a class=\"heading-anchor\" href=\"#django.core.files.File.mode\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>An modh léithe/scríbhneoireachta don chomhad.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.open\">\n<span class=\"sig-name descname\">open</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">mode<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"o\">*</span>args</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.File.open\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Open or reopen the file (which also does <code class=\"docutils literal notranslate\">File.seek(0)</code>).\nThe <code class=\"docutils literal notranslate\">mode</code> argument allows the same values\nas Python's built-in <a class=\"reference external\" href=\"https://docs.python.org/3/library/functions.html#open\" title=\"(in Python v3.14)\"><code class=\"docutils literal notranslate\">open()</code></a>. <code class=\"docutils literal notranslate\">*args</code> and <code class=\"docutils literal notranslate\">**kwargs</code>\nare passed after <code class=\"docutils literal notranslate\">mode</code> to Python's built-in <a class=\"reference external\" href=\"https://docs.python.org/3/library/functions.html#open\" title=\"(in Python v3.14)\"><code class=\"docutils literal notranslate\">open()</code></a>.</p>\n<p>Agus comhad á athoscailt, déanfaidh mod` athoscailt cibé modh a osclaíodh an comhad leis ar dtús; ciallaíonn <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">``</span></a>None <a href=\"#id3\"><span class=\"problematic\" id=\"id4\">``</span></a>athoscailt leis an modh bunaidh.</p>\n<p>Is féidir é a úsáid mar bhainisteoir comhthéacs, m.sh. with file.open () mar f: `.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.__iter__\">\n<span class=\"sig-name descname\">__iter__</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.File.__iter__\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Athraigh thar an gcomhad ag tabhairt líne amháin ag an am.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.chunks\">\n<span class=\"sig-name descname\">chunks</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">chunk_size<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.File.chunks\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Athraigh thar an gcomhad ag tabhairt “píosaí” de mhéid ar leith. Tá <code class=\"docutils literal notranslate\">chunk_size</code> réamhshocraithe go 64 KB.</p>\n<p>Tá sé seo úsáideach go háirithe le comhaid an-mhóra ós rud é go gceadaíonn sé iad a shruthú as diosca agus seachnaíonn sé an comhad iomlán a stóráil i gcuimhne.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.multiple_chunks\">\n<span class=\"sig-name descname\">multiple_chunks</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">chunk_size<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.File.multiple_chunks\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Tugann tuairisceáin <code class=\"docutils literal notranslate\">True</code> má tá an comhad mór go leor chun go dteastaíonn go leor píosaí chun rochtain a fháil ar a ábhar go léir, tugann roinnt <code class=\"docutils literal notranslate\">chunk_size</code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.close\">\n<span class=\"sig-name descname\">close</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.File.close\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Dún an comhad.</p>\n</dd></dl>\n\n<p>Chomh maith leis na modhanna liostaithe, nochtann :class: ~django.core.files.file na tréithe agus na modhanna seo a leanas dá réad <code class=\"docutils literal notranslate\">comhad ``: `encoding</code>, fileno`, <code class=\"docutils literal notranslate\">flush</code>, isatty`, newlines`, readin`, read `line` , `línte léite`, cuarda`, insint`, truncate`, scríbhneoireach`, scríbhneoireannaithe`, inléite () `, inscríofa ()`, agus <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">``</span></a>cuardaitheach () <a href=\"#id3\"><span class=\"problematic\" id=\"id4\">``</span></a>.</p>\n</dd></dl>\n\n</section>\n<section id=\"the-contentfile-class\">\n<h2>An rang <code class=\"docutils literal notranslate\">Contentfile</code><a class=\"heading-anchor\" href=\"#the-contentfile-class\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.base.ContentFile\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">ContentFile</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">content</em>, <em class=\"sig-param\">name<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.base.ContentFile\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Tá an rang <code class=\"docutils literal notranslate\">ContentFile</code> oidhreacht ó:class: ~django.core.files.file, ach ní cosúil:class: ~django.core.files.file oibríonn sé ar ábhar teaghrán (tacaíonn béite freisin), seachas comhad iarbhír. Mar shampla:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.files.base</span> <span class=\"kn\">import</span> ContentFile\n\nf1 <span class=\"o\">=</span> ContentFile<span class=\"p\">(</span><span class=\"s2\">&quot;esta frase está en español&quot;</span><span class=\"p\">)</span>\nf2 <span class=\"o\">=</span> ContentFile<span class=\"p\">(</span><span class=\"sa\">b</span><span class=\"s2\">&quot;these are bytes&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n</dd></dl>\n\n</section>\n<section id=\"the-imagefile-class\">\n<h2>An rang <code class=\"docutils literal notranslate\">Imagefile</code><a class=\"heading-anchor\" href=\"#the-imagefile-class\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.images.ImageFile\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">ImageFile</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">file_object</em>, <em class=\"sig-param\">name<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.images.ImageFile\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Soláthraíonn Django rang ionsuite go sonrach le haghaidh íomhánna. :class: Django.Core.Files.Images.ImageFile oidhreacht na tréithe agus na modhanna uile de:class: ~django.core.files.file, agus soláthraíonn sé an méid seo a leanas freisin:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.images.ImageFile.width\">\n<span class=\"sig-name descname\">width</span><a class=\"heading-anchor\" href=\"#django.core.files.images.ImageFile.width\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Leithead na híomhá i bpicteilíní.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.images.ImageFile.height\">\n<span class=\"sig-name descname\">height</span><a class=\"heading-anchor\" href=\"#django.core.files.images.ImageFile.height\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Airde na híomhá i bpicteilíní.</p>\n</dd></dl>\n\n</dd></dl>\n\n</section>\n<section id=\"additional-methods-on-files-attached-to-objects\">\n<h2>Modhanna breise ar chomhaid atá ceangailte le rudaí<a class=\"heading-anchor\" href=\"#additional-methods-on-files-attached-to-objects\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Aon: Class: Beidh cúpla modh breise ag Comhad a bhaineann le réad (mar atá le <code class=\"docutils literal notranslate\">Car.photo</code>, thíos) freisin:</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.save\">\n<span class=\"sig-prename descclassname\">File.</span><span class=\"sig-name descname\">save</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">content</em>, <em class=\"sig-param\">save<span class=\"o\">=</span><span class=\"default_value\">True</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.File.save\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Sábhálann comhad nua leis an ainm comhaid agus an t-ábhar a chuirtear ar fáil. Ní chuirfidh sé seo in ionad an comhad atá ann cheana, ach cruthóidh sé comhad nua agus nuashonróidh sé an réad chun cur in iúl dó. Más é <code class=\"docutils literal notranslate\">`Save</code> True`, glaofar modh <code class=\"docutils literal notranslate\">save () ``</code> an tsamhail nuair a shábháiltear an comhad. Is é sin, an dá líne seo:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>car<span class=\"o\">.</span>photo<span class=\"o\">.</span>save<span class=\"p\">(</span><span class=\"s2\">&quot;myphoto.jpg&quot;</span><span class=\"p\">,</span> content<span class=\"p\">,</span> save<span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>car<span class=\"o\">.</span>save<span class=\"p\">()</span>\n</code></pre></div>\n<p>atá coibhéiseach le:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>car<span class=\"o\">.</span>photo<span class=\"o\">.</span>save<span class=\"p\">(</span><span class=\"s2\">&quot;myphoto.jpg&quot;</span><span class=\"p\">,</span> content<span class=\"p\">,</span> save<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Tabhair faoi deara go gcaithfidh an argóint <code class=\"docutils literal notranslate\">content</code> a bheith ina shampla de: :class: File nó de fho-aicme de:class: File, mar shampla:class: ~django.core.files.base.contentfile.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.files.File.delete\">\n<span class=\"sig-prename descclassname\">File.</span><span class=\"sig-name descname\">delete</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">save<span class=\"o\">=</span><span class=\"default_value\">True</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.files.File.delete\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Baineann sé an comhad ón samhail samhail agus scriosann sé an comhad bunúsach. Más é <code class=\"docutils literal notranslate\">`Save</code> True`, glaofar modh <code class=\"docutils literal notranslate\">save () ``</code> an tsamhail nuair a scriosfar an comhad.</p>\n</dd></dl>\n\n</section>","rootId":"the-file-object","toc":[{"title":"An rang Comhad ``","anchor":"the-file-class","children":[]},{"title":"An rang Contentfile","anchor":"the-contentfile-class","children":[]},{"title":"An rang Imagefile","anchor":"the-imagefile-class","children":[]},{"title":"Modhanna breise ar chomhaid atá ceangailte le rudaí","anchor":"additional-methods-on-files-attached-to-objects","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"Tagairt API","url":"/ga/6.0/ref/"},{"docname":"ref/files/index","title":"Láimhseáil comhad","url":"/ga/6.0/ref/files/"}],"prev":{"docname":"ref/files/index","title":"Láimhseáil comhad","url":"/ga/6.0/ref/files/"},"next":{"docname":"ref/files/storage","title":"API stórála comhad","url":"/ga/6.0/ref/files/storage/"},"formats":{"html":"/ga/6.0/ref/files/file/","markdown":"/ga/6.0/ref/files/file.md","json":"/ga/6.0/ref/files/file.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/ref/files/file.txt","official":"https://docs.djangoproject.com/ga/6.0/ref/files/file/","inVersions":["6.1","6.0","5.2"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}