@@ -396,11 +396,13 @@ def _raw_list(self, path_, cls, **kwargs):
396396
397397 return results
398398
399- def _raw_post (self , path_ , data = None , content_type = None , ** kwargs ):
399+ def _raw_post (self , path_ , data = None , content_type = None ,
400+ files = None , ** kwargs ):
400401 url = '%s%s' % (self ._url , path_ )
401402 opts = self ._get_session_opts (content_type )
402403 try :
403- return self .session .post (url , params = kwargs , data = data , ** opts )
404+ return self .session .post (url , params = kwargs , data = data ,
405+ files = files , ** opts )
404406 except Exception as e :
405407 raise GitlabConnectionError (
406408 "Can't connect to GitLab server (%s)" % e )
@@ -628,7 +630,7 @@ def _build_url(self, path):
628630 return '%s%s' % (self ._url , path )
629631
630632 def http_request (self , verb , path , query_data = {}, post_data = {},
631- streamed = False , ** kwargs ):
633+ streamed = False , files = None , ** kwargs ):
632634 """Make an HTTP request to the Gitlab server.
633635
634636 Args:
@@ -658,6 +660,11 @@ def sanitized_url(url):
658660 params = query_data .copy ()
659661 params .update (kwargs )
660662 opts = self ._get_session_opts (content_type = 'application/json' )
663+
664+ # don't set the content-type header when uploading files
665+ if files is not None :
666+ del opts ["headers" ]["Content-type" ]
667+
661668 verify = opts .pop ('verify' )
662669 timeout = opts .pop ('timeout' )
663670
@@ -668,7 +675,7 @@ def sanitized_url(url):
668675 # always agree with this decision (this is the case with a default
669676 # gitlab installation)
670677 req = requests .Request (verb , url , json = post_data , params = params ,
671- ** opts )
678+ files = files , ** opts )
672679 prepped = self .session .prepare_request (req )
673680 prepped .url = sanitized_url (prepped .url )
674681 result = self .session .send (prepped , stream = streamed , verify = verify ,
@@ -756,7 +763,8 @@ def http_list(self, path, query_data={}, as_list=None, **kwargs):
756763 # No pagination, generator requested
757764 return GitlabList (self , url , query_data , ** kwargs )
758765
759- def http_post (self , path , query_data = {}, post_data = {}, ** kwargs ):
766+ def http_post (self , path , query_data = {}, post_data = {}, files = None ,
767+ ** kwargs ):
760768 """Make a POST request to the Gitlab server.
761769
762770 Args:
@@ -776,7 +784,7 @@ def http_post(self, path, query_data={}, post_data={}, **kwargs):
776784 GitlabParsingError: If the json data could not be parsed
777785 """
778786 result = self .http_request ('post' , path , query_data = query_data ,
779- post_data = post_data , ** kwargs )
787+ post_data = post_data , files = files , ** kwargs )
780788 try :
781789 if result .headers .get ('Content-Type' , None ) == 'application/json' :
782790 return result .json ()
0 commit comments