From: Martin Jul Date: Tue, 16 Sep 2014 09:38:40 +0000 (+0200) Subject: Added example of how to send multiple files in one request. X-Git-Tag: v2.4.2~12^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4707d11004a201a89257fa3ab5365fb3dc9d2f90;p=services%2Fpython-requests.git Added example of how to send multiple files in one request. --- diff --git a/AUTHORS.rst b/AUTHORS.rst index 1ab53ef..1e084d8 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -154,3 +154,4 @@ Patches and Suggestions - Константин Подшумок (`@podshumok `_) - Ben Bass (`@codedstructure `_) - Jonathan Wong (`@ContinuousFunction `_) +- Martin Jul (`@mjul `_) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 1a4b271..4c8a006 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -271,6 +271,30 @@ support this, but there is a separate package which does - `_ 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': + + + +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 ---------------------