()
| 1163 | pass |
| 1164 | |
| 1165 | async def stream_generator(): |
| 1166 | try: |
| 1167 | async with session.get(url) as resp: |
| 1168 | if resp.status != 200: |
| 1169 | raise HTTPException( |
| 1170 | status_code=resp.status, |
| 1171 | detail=f"文件获取失败{resp.status}: {await resp.text()}", |
| 1172 | ) |
| 1173 | chunk_size = 65536 |
| 1174 | while True: |
| 1175 | chunk = await resp.content.read(chunk_size) |
| 1176 | if not chunk: |
| 1177 | break |
| 1178 | yield chunk |
| 1179 | finally: |
| 1180 | await session.close() |
| 1181 | |
| 1182 | encoded_filename = quote(filename, safe='') |
| 1183 | headers = { |