def preview(pid, record, template=None, **kwargs):
<EOL>fileobj = current_previewer.record_file_factory(<EOL>pid, record, request.view_args.get(<EOL>'<STR_LIT:filename>', request.args.get('<STR_LIT:filename>', type=str))<EOL>)<EOL>if not fileobj:<EOL><INDENT>abort(<NUM_LIT>)<EOL><DEDENT>try:<EOL><INDENT>file_previewer = fileobj['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>file_previewer = None<EOL><DEDENT>fileobj = PreviewFile(pid, record, fileobj)<EOL>for plugin in current_previewer.iter_previewers(<EOL>previewers=[file_previewer] if file_previewer else None):<EOL><INDENT>if plugin.can_preview(fileobj):<EOL><INDENT>try:<EOL><INDENT>return plugin.preview(fileobj)<EOL><DEDENT>except Exception:<EOL><INDENT>current_app.logger.warning(<EOL>('<STR_LIT>'<EOL>.format(key=fileobj.file.key,<EOL>pid_type=fileobj.pid.pid_type,<EOL>pid_value=fileobj.pid.pid_value)),<EOL>exc_info=True)<EOL><DEDENT><DEDENT><DEDENT>return default.preview(fileobj)<EOL>
Preview file for given record.

    Plug this method into your ``RECORDS_UI_ENDPOINTS`` configuration:

    .. code-block:: python

        RECORDS_UI_ENDPOINTS = dict(
            recid=dict(
                # ...
                route='/records/<pid_value/preview/<path:filename>',
                view_imp='invenio_previewer.views.preview',
                record_class='invenio_records_files.api:Record',
            )
        )