0

The following function should output the file size of the image when sending a Post request from Insomnia/Postman API development environments.

@app.post("/user/photo") async def upload_user_photo(response: Response, profile_photo: bytes = File(...)): response.headers["x-file-size"] = str(len(profile_photo)) response.set_cookie(key="cookie-api", value="test") return {"file size": len(profile_photo)} 

However the following error occurs:

 File ".\run.py", line 54, in <module> async def upload_user_photo(response: Response, profile_photo: bytes = File(...)): NameError: name 'File' is not defined 

I've read that File() has been depreciated from Python 3, so what would be a way to get this to work?

1 Answer 1

4

The Python file function was deprecated. Remember that capitalization matters. What that code wants is the File class from fastapi. You need to add:

from fastapi import File 
Sign up to request clarification or add additional context in comments.

1 Comment

Ensure multipart package is also being installed. pip install python-multipart

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.