Uploading multiple files in a single request using python requests module

前端 未结 6 613
南笙
南笙 2020-12-04 19:49

The Python requests module provides good documentation on how to upload a single file in a single request:

 files = {\         


        
6条回答
  •  佛祖请我去吃肉
    2020-12-04 20:23

    You need to create a file list to upload multiple images:

    file_list = [  
           ('Key_here', ('file_name1.jpg', open('file_path1.jpg', 'rb'), 'image/png')),
           ('key_here', ('file_name2.jpg', open('file_path2.jpg', 'rb'), 'image/png'))
       ]
    
    r = requests.post(url, files=file_list)
    

    If you want to send files on the same key you need to keep the key same for each element, and for a different key just change the keys.

    Source : https://stackabuse.com/the-python-requests-module/

提交回复
热议问题