Skip to content

Commit

Permalink
Downgrade to FastAPI 0.68.2
Browse files Browse the repository at this point in the history
- Using this version of FastAPI gives us Starlette 0.14.2 which fixes a bug we faced
- Bug described at encode/starlette#1315
- Downgrading FastAPI means `UploadFile` is no longer supported. I've reverted to `File()` as an alternative solution, although `UploadFile` is probably easier to use, and I'd reimplement it in that way if we could upgrade in the future
  • Loading branch information
MRichards99 committed Jun 20, 2022
1 parent d0324ac commit ae28598
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 117 deletions.
16 changes: 7 additions & 9 deletions operationsgateway_api/src/routes/ingest_data.py
@@ -1,6 +1,6 @@
import logging

from fastapi import APIRouter, UploadFile
from fastapi import APIRouter, File

from operationsgateway_api.src.data_encoding import DataEncoding
from operationsgateway_api.src.hdf_handler import HDFDataHandler
Expand All @@ -21,12 +21,11 @@


@router.post("/submit_hdf", response_description="")
async def submit_hdf(file: UploadFile):
async def submit_hdf(file: bytes = File(default=None)):
log.info("Submitting CLF data in HDF file to be processed then stored in MongoDB")
log.debug("Filename: %s, Content: %s", file.filename, file.content_type)
#log.debug("Filename: %s, Content: %s", file.filename, file.content_type)

file_contents = await file.read()
hdf_file = HDFDataHandler.convert_to_hdf_from_request(file_contents)
hdf_file = HDFDataHandler.convert_to_hdf_from_request(file)

record, waveforms, images = HDFDataHandler.extract_hdf_data(hdf_file=hdf_file)
DataEncoding.encode_numpy_for_mongo(record)
Expand Down Expand Up @@ -81,12 +80,11 @@ async def submit_hdf(file: UploadFile):
response_description="Upload a HDF file, extract the contents and store the data in"
" MongoDB",
)
async def submit_hdf_basic(file: UploadFile):
async def submit_hdf_basic(file: File(default=None)):
log.info("Adding contents of attached file to MongoDB")
log.debug("Filename: %s, Content: %s", file.filename, file.content_type)
#log.debug("Filename: %s, Content: %s", file.filename, file.content_type)

file_contents = await file.read()
hdf_file = HDFDataHandler.convert_to_hdf_from_request(file_contents)
hdf_file = HDFDataHandler.convert_to_hdf_from_request(file)

# TODO - do something with these images
record, waveforms, images = HDFDataHandler.extract_hdf_data(hdf_file=hdf_file)
Expand Down

0 comments on commit ae28598

Please sign in to comment.