Reputation: 31
I would like to know if there is a way for FastAPI to receive a URL of a file as a parameter and save this file to disk? I know it is possible with the requests
library using requests.get()
method, but is it possible with FastAPI to receive the URL and save it directly?
I tried using file: UploadFile = File(...)
, but then it doesn't download the file when the URL is sent.
Upvotes: 1
Views: 348
Reputation: 11
I don't believe so. I've come across this before and was unable to find a solution (and ended up using requests like you mentioned), but seeing this I wanted to check again more thoroughly.
Reviewing the uvicorn
and fastapi
repositories by searching the code itself, I see no functions/code that reference requests
or urllib
(they do use urllib.parse
/quote
, etc though) that would be 2 likely suspects to build requests. They do use httpx.AsyncClient
, but only in tests. I would expect to see some use of these libraries in the main uvicorn
/fastapi
libraries if they had code to make external requests.
Seeing the above, I actually think I will change my code to use httpx.AsyncClient
anyways since it is already a dependency.
Upvotes: 1