Python file upload from url using requests library

后端 未结 2 1302
梦谈多话
梦谈多话 2021-01-18 17:04

I want to upload a file to an url. The file I want to upload is not on my computer, but I have the url of the file. I want to upload it using requests library. So, I want to

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-18 17:50

    There is an example in the documentation that may suit you. A file-like object can be used as a stream input for a POST request. Combine this with a stream response for your GET (passing stream=True), or one of the other options documented here.

    This allows you to do a POST from another GET without buffering the entire payload locally. In the worst case, you may have to write a file-like class as "glue code", allowing you to pass your glue object to the POST that in turn reads from the GET response.

    (This is similar to a documented technique using the Node.js request module.)

提交回复
热议问题