Batch upload media through rest API possible?

[ad_1]

My developer is trying to upload media through the rest API to the media library in batch, as we have thousands of files and making a request for each one takes too much time.

But it doesn’t seem to be possible… Is it?

def upload_image(files):
media_endpoint = f'{settings.BASE_WOOCOMMERCE_API}/wp-json/wp/v2/media’
# Send a POST request to upload the image
response = requests.post(url=media_endpoint,
auth=(settings.WP_USER, settings.WP_PASSWORD),
files=files)
print(response)

files is something like this

files = [(‘file’, open(‘report.xls’, ‘rb’)), (‘file’, open(‘report2.xls’, ‘rb’))]

Only one image gets uploaded…

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer