|
11 | 11 |
|
12 | 12 | import requests as rq |
13 | 13 |
|
14 | | -from .FileOperations import PrepareInput |
| 14 | +from .FileOperations import PrepareInput, CheckFile |
15 | 15 | from .config import HOST, JobStatus |
16 | 16 | from .parsers import ValidateResponse |
17 | 17 | from .common import ConvertTo |
@@ -98,6 +98,10 @@ def get_result(self, job_id: str, wait_time: int = 10, max_wait_time: int = 300) |
98 | 98 | time.sleep(max(10, int(wait_time))) |
99 | 99 | max_wait_time -= wait_time |
100 | 100 | resp = self._make_request('get', HOST.RESULT, params=params) |
| 101 | + |
| 102 | + if resp.get('DownloadUrl', ''): |
| 103 | + self.ServerResponse = rq.get(resp['DownloadUrl']) |
| 104 | + self.server_response = resp = self.ServerResponse.json() |
101 | 105 |
|
102 | 106 | return resp |
103 | 107 |
|
@@ -171,15 +175,16 @@ def process_file( |
171 | 175 | # To use the reference when saving the output |
172 | 176 | self.__setattr__('input_filename', os.path.basename(filepath)) |
173 | 177 |
|
174 | | - try: |
175 | | - with PrepareInput(filepath, pages=pages) as infile: |
176 | | - with open(infile.filepath, 'rb') as fp: |
| 178 | + with PrepareInput(filepath, pages=pages) as infile: |
| 179 | + with open(infile.filepath, 'rb') as fp: |
| 180 | + is_big_file = CheckFile(infile.filepath).is_big |
| 181 | + if not is_big_file: |
177 | 182 | trigger_resp = self.trigger_process(fp, dup_check=dup_check, **kwargs) |
178 | | - except ClientFileSizeError: |
179 | | - big_gen = self.bigfile_upload(filepath=os.path.basename(filepath)) |
180 | | - with open(filepath, 'rb') as ifile: |
181 | | - rq.post(big_gen['url'], data=big_gen['fields'], files={'file': ifile}) |
182 | | - trigger_resp = self.trigger_process(None, signed_filename=big_gen["fields"]["key"], dup_check=dup_check, **kwargs) |
| 183 | + else: |
| 184 | + big_gen = self.bigfile_upload(filepath=os.path.basename(infile.filepath)) |
| 185 | + with open(infile.filepath, 'rb') as ifile: |
| 186 | + rq.post(big_gen['url'], data=big_gen['fields'], files={'file': ifile}) |
| 187 | + trigger_resp = self.trigger_process(None, signed_filename=big_gen["fields"]["key"], dup_check=dup_check, **kwargs) |
183 | 188 |
|
184 | 189 | for _type, _obj in trigger_resp.items(): |
185 | 190 | self.__setattr__(_type, _obj) |
|
0 commit comments