Upload function accepts Bytes, BufferedReader type argument
SiegAndy opened this issue · comments
Is your feature request related to a problem? Please describe.
The upload function from API only accepts file name (string or path) as arguments. When we received the uploaded file from the client, it is in bytes, and we do not want to store it in a temp file and then send it to storage. We want to directly send bytes to storage.
Describe the solution you'd like
Just three line of code need to be added to file_api.py:
from files = {"file": (filename, open(file, "rb"), headers.pop("content-type"))}
to
if isinstance(file, BufferedReader) or isinstance(file, bytes):
files = {"file": (filename, file, headers.pop("content-type"))}
else:
files = {"file": (filename, open(file, "rb"), headers.pop("content-type"))}
@SiegAndy thanks for making the issue, would you like to open the PR yourself? I'd be happy to review and merge
We could also probably accept pathlib.Path
objects here
Sure sure. I opened a PR for this and the datetime error