]> jfr.im git - z_archive/twitter.git/commitdiff
fix image sending to handle both base64 images and plain bytes
authorRouxRC <redacted>
Tue, 22 Jul 2014 22:24:37 +0000 (00:24 +0200)
committerRouxRC <redacted>
Tue, 22 Jul 2014 22:24:37 +0000 (00:24 +0200)
twitter/api.py

index be0ef43f3add9f2e9c67a335e004f227b83906c3..28979b581de4779d5cea3f1f226a2c20c34aa47f 100644 (file)
@@ -205,6 +205,13 @@ class TwitterCall(object):
         for arg in ['media[]', 'banner', 'image']:
             if arg in kwargs:
                 media = kwargs.pop(arg)
+                # Check if argument tells whether img is already base64 encoded
+                b64_convert = True
+                if "_base64" in kwargs:
+                    b64_convert = not kwargs.pop("_base64")
+                if b64_convert:
+                    import base64
+                    media = base64.b64encode(media)
                 mediafield = arg
                 break
 
@@ -229,6 +236,7 @@ class TwitterCall(object):
             bod.append('--' + BOUNDARY)
             bod.append(
                 'Content-Disposition: form-data; name="%s"' % mediafield)
+            bod.append('Content-Transfer-Encoding: base64')
             bod.append('')
             bod.append(media)
             for k, v in kwargs.items():