David Li commited on
Commit
7b2aa18
·
1 Parent(s): 4b9b9cb

fix: deta file stuff by properly using streamiing

Browse files
Files changed (1) hide show
  1. main.py +3 -11
main.py CHANGED
@@ -44,17 +44,9 @@ async def get_files(exchange: str = "US"):
44
 
45
 
46
  # get file by name from deta /file/{id}
 
47
  @app.get("/file/{id}")
48
  async def get_file(id: str):
49
- output_file = drive.get(id)
50
- # return file
51
- # content = output_file.read()
52
-
53
- content = output_file.read()
54
- output_file.close()
55
- headers = {
56
- 'Content-Disposition': f'attachment; filename="{id}"'
57
- }
58
- bytesio_object = BytesIO(content)
59
- return StreamingResponse(bytesio_object, headers=headers)
60
 
 
44
 
45
 
46
  # get file by name from deta /file/{id}
47
+ # reason it was likely failing is because of the response size limit
48
  @app.get("/file/{id}")
49
  async def get_file(id: str):
50
+ res = drive.get(id)
51
+ return StreamingResponse(res.iter_chunks(1024), media_type="application/pdf")
 
 
 
 
 
 
 
 
 
52