Replies: 4 comments 1 reply
-
I'm not very familiar with MinIO, but if from fastapi import FastAPI, File, UploadFile
@app.post("/upload")
async def (file: UploadFile = File(...)):
result = minio_client.put_object(
"files",
"object",
data=file,
content_type=file.content_type
) The good thing with Ref: https://fastapi.tiangolo.com/tutorial/request-files/#file-parameters-with-uploadfile |
Beta Was this translation helpful? Give feedback.
-
Yes, that was my first approach, too. What I did in the end: |
Beta Was this translation helpful? Give feedback.
-
I see! Another solution I already used is to actually directly upload to the S3 server, without passing through an intermediate API. From your backend, It's possible to generate a presigned (authenticated) URL on your S3 bucket, which you return to your client browser. This URL allows the browser to directly upload the data to the bucket. |
Beta Was this translation helpful? Give feedback.
-
For anyone looking for a solution, here is mine that actually works: ...
file_content = file.file
file_content.seek(0, os.SEEK_END)
file_size = file_content.tell()
file_content.seek(0)
result = minio_client.put_object(
"files",
"object",
data=file_content,
content_type=file.content_type,
length=file_size
) |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
Hello :)
I would like to upload POSTed files directly to MinIO object storage.
I want to stream files directly from the body to Minio, to avoid multiple copies of the file on the server.
Also I would like to avoid the UploadFile API, because I would like to avoid the overhead for multipart-parsing for bigger files.
I just can't wrap my head around how to get the chunks from the async generator from the request.stream to a read() interface as the Minio Client expects.
The example above doesn't work how I want, as the call will just simply replace previous put operations.
Also I just can't put request.stream in, as the minio_client can't handle the generator. It expects an object with a read() interface.
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.78.0
Python Version
3.8.15
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions