How to serve a file from mongodb with golang

Hello

I am working on a go project where I need to serve files stored in mongodb. The files are stored in a GridFs. I use gopkg.in/mgo.v2 as package to connect and query the db.

I can retrieve the file from the db, that is not hard.

f, err := s.files.OpenId(id)

But how can I serve that file with http? I work with the Julien Schmidt router to handle all the other restfull requests. The solutions I find always use static files, not files from a db.

Github:
github repo

Thanks in advance

Found it…
GridFile implements ReadSeeker, so just serveContent does the trick.
I thought it only implemented the Reader interface…

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.