Upload Image using POST form data in Python-requests

前端 未结 7 1816
醉话见心
醉话见心 2020-11-27 04:16

I\'m working with wechat APIs ... here I\'ve to upload an image to wechat\'s server using this API http://admin.wechat.com/wiki/index.php?title=Transferring_Multimedia_Files

7条回答
  •  感动是毒
    2020-11-27 04:34

    client.py

    files = {
        'file': (
            os.path.basename('path/to/file'), 
            open('path/to/file', 'rb'), 
            'application/octet-stream'
        )
    }
    requests.post(url, files=files)
    

    server.py

    @app.route('/', methods=['POST'])
    def index():
    
        picture = request.files.get('file')
        picture.save('path/to/save')
    
        return 'ok', 200
    

提交回复
热议问题