Added example of how to send multiple files in one request.
authorMartin Jul <martin@mjul.com>
Tue, 16 Sep 2014 09:38:40 +0000 (11:38 +0200)
committerMartin Jul <martin@mjul.com>
Tue, 16 Sep 2014 09:38:40 +0000 (11:38 +0200)
AUTHORS.rst
docs/user/quickstart.rst

index 1ab53ef83a78b3724331b9f1fe820e40f14109c0..1e084d8f6b129ba563a2169e273f9a76e94bfb20 100644 (file)
@@ -154,3 +154,4 @@ Patches and Suggestions
 - Константин Подшумок (`@podshumok <https://github.com/podshumok>`_)
 - Ben Bass (`@codedstructure <https://github.com/codedstructure>`_)
 - Jonathan Wong <evolutionace@gmail.com> (`@ContinuousFunction <https://github.com/ContinuousFunction>`_)
+- Martin Jul (`@mjul <https://github.com/mjul>`_)
index 1a4b2714590bedbccd989fcc9fdae0ace1412c72..4c8a006b44c432405398e77cfb9015574dcef5c8 100644 (file)
@@ -271,6 +271,30 @@ support this, but there is a separate package which does -
 <https://toolbelt.rtfd.org>`_ for more details about how to use it.
 
 
+POST Multiple Multipart-Encoded Files
+-------------------------------------
+
+You can send multiple files in one request. For example, suppose you want to
+upload image files to an HTML form with a multiple file field 'images':
+
+    <input type="file" name="images" multiple="true" required="true"/>
+
+To do that, just set files to a list of tuples of (form_field_name, file_info):
+
+    >>> url = 'http://httpbin.org/post'
+    >>> multiple_files = [('images', ('foo.png', open('foo.png', 'rb'), 'image/png')),
+                          ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))]
+    >>> r = requests.post(url, files=multiple_files)
+    >>> r.text
+    {
+      ...
+      'files': {'images': 'data:image/png;base64,iVBORw ....'}
+      'Content-Type': 'multipart/form-data; boundary=3131623adb2043caaeb5538cc7aa0b3a',
+      ...
+    }
+
+
+
 Response Status Codes
 ---------------------