0

Given a file from GridFS, I'd like to be able to display it on a webpage. The files in my database can be of any common type, including jpgs, pngs, xml, txt, csv, etc.

A user would like to be able to click on the name of the file and in a new tab the file is displayed whether it is an image or text file, or click download and download the file with its original extension.

The application is in Python. I have seen some solution on here, but they require reading the bytes into a buffer, concatenating, and formatting some markup for an image with the bytes as a base64 string and require that the programmer knows what the extension of the file is and for the code to handle and format each extension case separately.

Village
  • 199
  • 3
  • 15
  • What language? What have you tried? Where's the code? Why didn't it work? etc.. etc... [How to ask a question](http://stackoverflow.com/help/how-to-ask) – chrisbajorin Feb 26 '16 at 22:55
  • The application is in Python as you'll see in the tags, but it doesn't matter what language at all, it could even be done through the command prompt for all I care. I'm asking how best to do this, so there is no code. As to why other solutions don't work, because I have only seen solutions that download as an array of bytes or stream, I need my file back the way I stored it, e.g., as an xml or image, etc. – Village Feb 26 '16 at 23:37
  • Don't worry about the displaying part, that doesn't matter. My question more generally is after I insert a file into MongoDB how do I get it back as I inserted it. Everyone I see on StackOverflow and elsewhere is concatenating the bytes with a buffer and outputting it to a file or some markup tag, that is not the solution I'm looking for. What I am asking for may not be possible. – Village Feb 26 '16 at 23:39
  • I highly suspect that the answer is "that isn't possible, GridFS doesn't do that/work like that." – Village Feb 26 '16 at 23:40
  • 1
    Here is one GridFs js version which I used before, https://gist.github.com/richzw/3215815, hope it could help you... – zangw Feb 27 '16 at 01:15
  • " but it doesn't matter what language at all," It does, because this a programming Q&A site. Regardless, it's definitely possible, and you've still given no way for anyone to help you. You have no code and not even an explanation of something tangible you've tried, which means you'll get no tangible answer. Again, I recommend re-reading "How to ask a question", as it tends to be highly correlated with "How to get an answer". – chrisbajorin Feb 27 '16 at 04:02
  • Thanks, zangw! This is a good resource for understanding how the process works. – Village Feb 29 '16 at 19:18

0 Answers0