Hello I need to send multiple image files in array via post request in python to my API. Problem is that I always see only one file. Simplified version of code is
import requests
url = 'https://v******p.sk/api/products'
imageFiles = [
('images', open('images/1.jpg', 'rb')),
('images', open('images/2.jpg', 'rb')),
('images', open('images/3.jpg', 'rb'))
]
r = requests.post(url, files=imageFiles)
print(r.text)
API has one images input which accept array of files so I don't want to use something like
imageFiles = [
('image1', open('images/1.jpg', 'rb')),
('image2', open('images/1.jpg', 'rb')),
('image3', open('images/1.jpg', 'rb'))
]
Now I set my API to echo just
print_r($_FILES);
When I try to post files from POSTMAN it works as expected and return something like this:
Array
(
[images] => Array
(
[name] => Array
(
[0] => 1.jpg
[1] => 2.jpg
[2] => 3.jpg
)
[full_path] => Array
(
[0] => 1.jpg
[1] => 2.jpg
[2] => 3.jpg
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
[2] => image/jpeg
)
[tmp_name] => Array
(
[0] => /data/4/.tmp/upload/php94o87g
[1] => /data/4/.tmp/upload/phpoBeKRB
[2] => /data/4/.tmp/upload/phpYCa8dM
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
[size] => Array
(
[0] => 112073
[1] => 186980
[2] => 186980
)
)
)
But when I try from python, I get just one file:
Array
(
[images] => Array
(
[name] => 3.jpg
[full_path] => 3.jpg
[type] =>
[tmp_name] => /data/php537KO4
[error] => 0
[size] => 154584
)
)
How to post array of files with same key please? I checked many posts on the web and the first approach should be working, but it's not. Thank you very much in advance.