# URI Multipart for Image file

**URL:** <https://forum.ansible.com/t/uri-multipart-for-image-file/35780>\
**Category:** Ansible Project\
**Created:** [September 24, 2021, 8:18am UTC](https://forum.ansible.com/t/uri-multipart-for-image-file/35780 "2021-09-24T08:18:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amitchettri](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/amitchettri/32/404_2.png) [@amitchettri](https://forum.ansible.com/u/amitchettri)\
**Post date:** [September 24, 2021, 8:18am UTC](https://forum.ansible.com/t/uri-multipart-for-image-file/35780/1 "2021-09-24T08:18:49Z")

</div>

Hello All,

I am trying to upload the image using below URI API call with multipart/form-data as i have almost 1 to 6 image to be uploaded at a time.

For testing i am only trying with the image 1.

Task work as expected but the issue is upload image are all scattered. I tried to upload using the curl and with GUI work perfectly.

Can anyone help.

- name: multipart api call  
uri:  
url: “IP/api/xxxx/images”  
method: POST  
headers:  
Content-Type: “multipart/form-data”  
Authorization: “Bearer {{ access\_token }}”  
validate\_certs: \<true/false\>  
body\_format: form-multipart  
body:  
image1:  
content: “{{ lookup(‘file’, ‘path\_to\_image.jpg’)}}”  
filename: “path\_to\_image.jpg”  
type: image/jpg  
register: register\_uri\_val

delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 24, 2021, 1:26pm UTC](https://forum.ansible.com/t/uri-multipart-for-image-file/35780/2 "2021-09-24T13:26:18Z")

</div>

You cannot use `lookup` to get the image, because the templating engine will attempt to convert everything to utf-8 text within the data.

Just use the path to the image in the `filename`, and drop `content`

---

<div class="post-metadata">

**Author:** ![amitchettri](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/amitchettri/32/404_2.png) [@amitchettri](https://forum.ansible.com/u/amitchettri)\
**Post date:** [September 24, 2021, 2:07pm UTC](https://forum.ansible.com/t/uri-multipart-for-image-file/35780/3 "2021-09-24T14:07:00Z")

</div>

Hi Matt,

Thank you for the revert. I have tried with that approach already as below but then i get the error pasted below. Only way pass through for me was with the content but image pixel are all blown out

body:  
image1:  
filename: “path\_to\_image.jpg”  
mime\_type/type: image/jpg  
register: register\_uri\_val

delegate\_to: localhost

Error  
fatal: [IP → localhost]: FAILED! =\> {“cache\_control”: “no-cache, no-store”, “changed”: false, “connection”: “close”, “content\_security\_policy”: “default-src ‘self’ ‘unsafe-inline’ [https://www.gstatic.com](https://www.gstatic.com) \*.[githubusercontent.com](http://githubusercontent.com) data: blob: ws: wss:; script-src ‘self’ ‘unsafe-inline’ [https://www.gstatic.com](https://www.gstatic.com)”, “content\_type”: “application/json;charset=UTF-8”, “date”: “Fri, 24 Sep 2021 13:53:46 GMT”, “elapsed”: 0, “expires”: “-1”, “feature\_policy”: “vibrate ‘none’ ; microphone \* ; camera ‘none’ ; gyroscope ‘none’ ; magnetometer ‘none’ ; geolocation ‘none’ ; midi ‘self’ ; notifications ‘self’ ; push ‘self’ ; sync-xhr ‘self’”, “json”: {“msg”: “Looks like the server threw a gasket”, “success”: false}, “msg”: "Status code was 500 and not [200]: HTTP Error 500: ", “pragma”: “no-cache”, “redirected”: false, “referrer\_policy”: “same-origin”, “set\_cookie”: “JSESSIONID=E8xxxxxxxxxxxxxxxxxxxxxA950E38; Path=/; Secure; HttpOnly”, “status”: 500, “strict\_transport\_security”: “max-age=31536000”, “transfer\_encoding”: “chunked”, “url”: “[https://192.x.x.x/api/settings/images](https://192.x.x.x/api/settings/images)”, “x\_content\_type\_options”: “nosniff”, “x\_frame\_options”: “SAMEORIGIN”}

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 24, 2021, 2:12pm UTC](https://forum.ansible.com/t/uri-multipart-for-image-file/35780/4 "2021-09-24T14:12:14Z")

</div>

Haha, that error message from the server isn’t exactly helpful:

> Looks like the server threw a gasket

I cannot really say without either seeing a working curl command, or knowing more about what caused the 500 ISE.

I do notice your latest task says “mime\_type/type”, which should just be “mime\_type”
