From e9a4d22683ace5d4d92a0254017a20d8df976f40 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Fri, 6 Jun 2025 09:23:47 +0200 Subject: [PATCH] correctly encode content uploads as multipart/form-data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit before this, they were encoded as application/x-www-form-urlencoded, and while this technically works, it makes the request 2-3× larger, sometimes hitting limits in Rack/Rails. Fixes: #1862 --- changelogs/fragments/1862-content-upload-multipart.yml | 2 ++ plugins/modules/content_upload.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/1862-content-upload-multipart.yml diff --git a/changelogs/fragments/1862-content-upload-multipart.yml b/changelogs/fragments/1862-content-upload-multipart.yml new file mode 100644 index 0000000000..beb74bcefe --- /dev/null +++ b/changelogs/fragments/1862-content-upload-multipart.yml @@ -0,0 +1,2 @@ +bugfixes: + - content_upload - correctly encode content uploads as multipart/form-data (https://github.com/theforeman/foreman-ansible-modules/issues/1862) diff --git a/plugins/modules/content_upload.py b/plugins/modules/content_upload.py index 80616f25a3..e0ed777a00 100644 --- a/plugins/modules/content_upload.py +++ b/plugins/modules/content_upload.py @@ -203,8 +203,9 @@ def main(): with open(b_src, 'rb') as contentfile: for chunk in iter(lambda: contentfile.read(CONTENT_CHUNK_SIZE), b""): - data = {'content': chunk, 'offset': offset, 'size': size} - module.resource_action('content_uploads', 'update', params=content_upload_scope, data=data) + data = {'offset': offset, 'size': size} + files = {'content': chunk} + module.resource_action('content_uploads', 'update', params=content_upload_scope, data=data, files=files) offset += len(chunk)