From 68d0f370a28f9b14bbc15156e80901e504691d5b Mon Sep 17 00:00:00 2001 From: bsimjoo Date: Tue, 14 Jul 2020 12:44:29 +0430 Subject: [PATCH 1/2] lower memory usage while uploading file --- client.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client.py b/client.py index 90f04a2..a847cbe 100644 --- a/client.py +++ b/client.py @@ -328,8 +328,14 @@ def upload_file(self, file_path): raise ValueError('Invalid file') try: - file = {'file': open(file_path, 'rb')} - response = requests.post(self.get_upload_file_url(), files=file) + session = requests.Session() + with open(file_path, "rb") as f: + m = MultipartEncoder({ + 'file':(file_path.split('/')[-1],f,"application/octet-stream") + }) + headers = {"Content-Type": m.content_type} + response = session.post(self.get_upload_file_url(),headers=headers, data=m) + session.close() if response.status_code == 200: if response: From e4c4125911f2c227b61e5a38e08c7ffce3fd3a46 Mon Sep 17 00:00:00 2001 From: bsimjoo Date: Tue, 14 Jul 2020 22:43:28 +0430 Subject: [PATCH 2/2] forgot importing MultipartEncoder --- client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client.py b/client.py index a847cbe..3e1454d 100644 --- a/client.py +++ b/client.py @@ -1,4 +1,5 @@ import requests +from requests_toolbelt.multipart.encoder import MultipartEncoder import sseclient import json import os