Skip to content

Commit 69561fd

Browse files
committed
feat: support multipart uploads
1 parent 265dbbd commit 69561fd

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

gitlab/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
from gitlab.const import * # noqa
2828
from gitlab.exceptions import * # noqa
2929
from gitlab import utils # noqa
30+
from requests_toolbelt.multipart.encoder import MultipartEncoder
31+
3032

3133
__title__ = "python-gitlab"
32-
__version__ = "2.5.0"
34+
__version__ = "2.6.0"
3335
__author__ = "Gauvain Pocentek"
3436
__email__ = "gauvainpocentek@gmail.com"
3537
__license__ = "LGPL3"
@@ -496,9 +498,12 @@ def http_request(
496498

497499
# We need to deal with json vs. data when uploading files
498500
if files:
499-
data = post_data
501+
my_data = post_data
500502
json = None
501-
del opts["headers"]["Content-type"]
503+
my_data["file"] = files["file"]
504+
files = None
505+
data = MultipartEncoder(my_data)
506+
opts["headers"]["Content-type"] = data.content_type
502507
else:
503508
json = post_data
504509
data = None

gitlab/v4/objects/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ def import_group(self, file, path, name, parent_id=None, **kwargs):
16151615
Returns:
16161616
dict: A representation of the import status.
16171617
"""
1618-
files = {"file": ("file.tar.gz", file)}
1618+
files = {"file": ("file.tar.gz", file, "application/octet-stream")}
16191619
data = {"path": path, "name": name}
16201620
if parent_id is not None:
16211621
data["parent_id"] = parent_id
@@ -5488,8 +5488,8 @@ def import_project(
54885488
Returns:
54895489
dict: A representation of the import status.
54905490
"""
5491-
files = {"file": ("file.tar.gz", file)}
5492-
data = {"path": path, "overwrite": overwrite}
5491+
files = {"file": ("file.tar.gz", file, "application/octet-stream")}
5492+
data = {"path": path, "overwrite": str(overwrite)}
54935493
if override_params:
54945494
for k, v in override_params.items():
54955495
data["override_params[%s]" % k] = v

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests==2.24.0
2+
requests-toolbelt>=0.9.1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_version():
2626
license="LGPLv3",
2727
url="https://github.com/python-gitlab/python-gitlab",
2828
packages=find_packages(),
29-
install_requires=["requests>=2.22.0"],
29+
install_requires=["requests>=2.22.0", "requests-toolbelt>=0.9.1"],
3030
python_requires=">=3.6.0",
3131
entry_points={"console_scripts": ["gitlab = gitlab.cli:main"]},
3232
classifiers=[

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy