def get_file(file_id: str, download):
    """
    Get a specific file from GridFS.

    Returns a binary stream response or HTTP 404 if not found.
    """
    data = current_app.config["data"]  # type: DataStorage
    dao = data.get_files_dao()
    file_fp, filename, upload_date = dao.get(file_id)

    if download:
        mime = mimetypes.guess_type(filename)[0]
        if mime is None:
            # unknown type
            mime = "binary/octet-stream"

        basename = os.path.basename(filename)
        return send_file(file_fp, mimetype=mime, attachment_filename=basename, as_attachment=True)

    else:
        rawdata = file_fp.read()
        try:
            text = rawdata.decode('utf-8')
        except UnicodeDecodeError:
            # not decodable as utf-8
            text = _get_binary_info(rawdata)
        html = render_template("api/file_view.html", content=text)
        file_fp.close()
        return Response(html)
Get a specific file from GridFS.

    Returns a binary stream response or HTTP 404 if not found.