user133580
user133580

Reputation: 1509

How to streaming upload with python requests module (include file and data)?

I have this code python requests code snippet(part) to upload a file and some data to the server:

files = [("FileData", (upload_me_name, open(upload_me, "rb"), "application/octet-stream"))]
r = s.post(url, proxies = proxies, headers = headers, files = files, data = data)

Since this will read the whole file into memory, which may cause some issues in some situations. From the requests documentation, I know it supports streaming uploads like this:

with open('massive-body') as f:
    requests.post('http://some.url/streamed', data=f)

However I don't know how to change my original code to support streaming. Anyone can help please?

Thanks.

Upvotes: 4

Views: 4588

Answers (1)

Lukasa
Lukasa

Reputation: 15518

Currently requests doesn't support doing streaming uploads that contain any more data than a single file. The fact that you're sending data on your POST means you're doing a multipart file upload, and currently Requests doesn't provide you with any way to stream that.

Upvotes: 5

Related Questions