Giter Club home page Giter Club logo

Comments (3)

art049 avatar art049 commented on May 22, 2024 2

Hello thanks for the feedback πŸŽ‰.
I didn't really thought yet about GridFS use with odmantic but maybe this issue is the opportunity for starting documenting this πŸ˜„ .

Basically, I think it should be quite easy to use GridFS externally.
First, you'll probably need to pass a motor client instance to the AIOEngine so you'll be able to reuse it later for accessing the files.
You could then add ObjectId field referencing your files in Odmantic models.
Finally you'll be able to query the files from the motor client directly.

I would really like to integrate GridFS Files to odmantic but I think it should come with Lazy loading and maybe streaming capabilities. This will probably be a good time to address this once lazy references will be handled πŸ˜‰

from odmantic.

erny avatar erny commented on May 22, 2024

Hi, thanks for your quick answer. Adding object Id(s) to reference files could be a good way to start.

Lazy loading is already provided by motor AFAIK and streaming shouldn't be very difficult. I was thinking about a thin layer for searching / getting files and accessing streams, something like (to be consistent with existing API):

...
from fastapi.responses import StreamingResponse
from odmantic import AIOEngine, File
engine = AIOEngine()

@app.get("/filestreams/", name: Optional[str]):
    file = await engine.find_one(File, File.name == "myfile.pdf")
    return StreamingResponse(await file.open_download_stream(), media_type=file. content_type)

so odmantic.File would really be a Model like class with some extras. It seems that the attributes are fixed anyway (name/filename, content_type, length, md5. upload_date, closed, chunksize, metadata) but taking into account AsyncIOMotorGridFSBucket , AsyncIOMotorGridIn, AsyncIOMotorGridOut there are a lot of methods (delete, rename, open_download_stream, open_upload_stream, download_to_stream, upload_from_stream, abort, close, set, write, writelines, read, readline, close).

Regards.

from odmantic.

tpougy avatar tpougy commented on May 22, 2024

Any news about this? I am really interested in using ODMantic with GridFS support.

from odmantic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.