changeset 68:4645e50539ff

Add support for posting files with own form names for each file Add a multi param to mergeclient to show example of posting each file as its own formular parameter.
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 02 Dec 2014 17:06:33 +0100
parents 5d1e486140ae
children dcf870775c26
files mergeclient.py
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mergeclient.py	Mon Dec 01 16:04:32 2014 +0100
+++ b/mergeclient.py	Tue Dec 02 17:06:33 2014 +0100
@@ -15,6 +15,8 @@
     parser.add_option("-o", "--out", default="merged.pdf", dest="out")
     parser.add_option("-i", "--ignore-file-errors", action="store_true",
                       default=False, dest="ignorefileerrors")
+    parser.add_option("-m", "--multi", action="store_true",
+                      default=False, dest="multi")
     (options, args) = parser.parse_args()
 
     if len(args) < 2:
@@ -29,8 +31,12 @@
 
     files = []
 
-    for filename in args:
-        files.append(('files', open(filename, 'rb')))
+    if options.multi:
+        for i, filename in enumerate(args):
+            files.append(("file%s" % i, open(filename, 'rb')))
+    else:
+        for filename in args:
+            files.append(('files', open(filename, 'rb')))
 
     r = requests.post(url, files=files)
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)