Ticket #10400: fileupload.3.diff

File fileupload.3.diff, 3.3 KB (added by Tim Graham, 15 years ago)

added metadata targets

  • docs/topics/http/file-uploads.txt

     
    99.. versionadded:: 1.0
    1010
    1111When Django handles a file upload, the file data ends up placed in
    12 ``request.FILES`` (for more on the ``request`` object see the documentation for
    13 :ref:`request and response objects <ref-request-response>`). This document
    14 explains how files are stored on disk and in memory, and how to customize the
    15 default behavior.
     12:attr:`request.FILES <django.http.HttpRequest.FILES>` (for more on the
     13``request`` object see the documentation for :ref:`request and response objects
     14<ref-request-response>`). This document explains how files are stored on disk
     15and in memory, and how to customize the default behavior.
    1616
    1717Basic file uploads
    1818==================
    1919
    20 Consider a simple form containing a ``FileField``::
     20Consider a simple form containing a :class:`~django.db.models.FileField`::
    2121
    2222    from django import forms
    2323
     
    2525        title = forms.CharField(max_length=50)
    2626        file  = forms.FileField()
    2727
    28 A view handling this form will receive the file data in ``request.FILES``, which
    29 is a dictionary containing a key for each ``FileField`` (or ``ImageField``, or
    30 other ``FileField`` subclass) in the form. So the data from the above form would
     28A view handling this form will receive the file data in
     29:attr:`request.FILES <django.http.HttpRequest.FILES>`, which is a dictionary
     30containing a key for each :class:`~django.db.models.FileField` (or
     31:class:`~django.db.models.ImageField`, or other :class:`~django.db.models.FileField`
     32subclass) in the form. So the data from the above form would
    3133be accessible as ``request.FILES['file']``.
    3234
     35Note that :attr:`request.FILES <django.http.HttpRequest.FILES>` will only
     36contain data if the request method was ``POST`` and the ``<form>`` that posted
     37to the request has the attribute ``enctype="multipart/form-data"``. Otherwise,
     38``FILES`` will be a blank dictionary-like object.
     39
    3340Most of the time, you'll simply pass the file data from ``request`` into the
    3441form as described in :ref:`binding-uploaded-files`. This would look
    3542something like::
     
    5057            form = UploadFileForm()
    5158        return render_to_response('upload.html', {'form': form})
    5259
    53 Notice that we have to pass ``request.FILES`` into the form's constructor; this
    54 is how file data gets bound into a form.
     60Notice that we have to pass :attr:`request.FILES <django.http.HttpRequest.FILES>`
     61into the form's constructor; this is how file data gets bound into a form.
    5562
    5663Handling uploaded files
    5764-----------------------
    5865
    5966The final piece of the puzzle is handling the actual file data from
    60 ``request.FILES``. Each entry in this dictionary is an ``UploadedFile`` object
    61 -- a simple wrapper around an uploaded file. You'll usually use one of these
    62 methods to access the uploaded content:
     67:attr:`request.FILES <django.http.HttpRequest.FILES>`. Each entry in this
     68dictionary is an ``UploadedFile`` object -- a simple wrapper around an uploaded
     69file. You'll usually use one of these methods to access the uploaded content:
    6370
    6471    ``UploadedFile.read()``
    6572        Read the entire uploaded data from the file. Be careful with this
Back to Top