0

I am new to Pyton fastAPI and Kubernetes and developing a REST-API with Python's fastAPI which will run in a Kubernetes environment. The API will receive files or images from the client by following code:

@app.post("/FileUpload/")
async def upload_file(file: UploadFile = File(...)):
...
return {"filename": file.filename}

This file should be uploaded after receiving to snowflake without any processing by following code

sql = f'''PUT 'file://{file}'   '@{snowflake_connector.PAYLOAD_STAGE}/{snowflake_connector.PAYLOAD_STAGE_PATH}' AUTO_COMPRESS=FALSE;'''

and pandas method read_sql(query, connection) to snowflake.

Unfortunately I did not found a solution to upload the received file on the fly, so the file must be chached. What would be the best way to achive this? Or am I missig something?

I am using Python 3.7.7.

Any help is appreciated.

holzflo
  • 31
  • 2
  • Perhaps it will be helpful https://stackoverflow.com/questions/63580229/how-to-save-uploadfile-in-fastapi/63581187 – alex_noname Jan 15 '21 at 08:36
  • Unfortunately it is not working. Following error is displayed: sqlalchemy.exc.ProgrammingError: (snowflake.connector.errors.ProgrammingError) 253006: File doesn't exist: [''] [SQL: PUT 'file://' '@lp_lake.stage.internal_binary_1/ddl_files/' AUTO_COMPRESS=FALSE;] – holzflo Jan 18 '21 at 05:56
  • the question is a bit all over the place, you have an image, but want to use a Pandas DataFrame. If you have the data in a DataFrame you can use to_sql(). https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html – Rick Jan 18 '21 at 10:57

0 Answers0