【问题标题】:VichUploaderBundle - Serving files in ekkoLightbox with a controllerVichUploaderBundle - 使用控制器在 ekkoLightbox 中提供文件
【发布时间】:2020-01-10 16:48:05
【问题描述】:

我在我的 Symfony 4 项目中使用 VichUploaderBundle 包来上传附件。 上传效果很好,但我很烦显示这些附件。

我使用插件“ekko-lightbox”(或其他插件,如果你知道更好?),直接向用户显示附件而不离开页面,但我得到了很多奇怪的字符......。

这是我的代码(我使用控制器来检查用户是否有权下载文件):

/**
 * @Route("/ticket/attachment/{id}", name="ticketing_attachments", methods="GET")
 * @IsGranted("ROLE_USER")
 */
public function getTicketAttachment(TicketAttachment $ticketAttachment, DownloadHandler $downloadHandler, TicketManager $ticketManager): Response
{
    if(!$ticketManager->hasPermissionViewTicket($ticketAttachment->getTicket(), $this->getUser())) {
        throw new HttpException(404, 'La page que vous avez demandée n\'existe pas.', null, [], 1);
    }

    return $downloadHandler->downloadObject($ticketAttachment, $fileField = 'file', $objectClass = null, $fileName = null, $forceDownload = false);
}

树枝:

{% if ticket.attachments|length > 0 %}
     <hr/>
     {% for attachment in ticket.attachments %}
           <span class="glyphicon glyphicon-paperclip"></span>
           <a href="{{ path('ticketing_attachments', {id: attachment.id}) }}" data-toggle="lightbox">{{ attachment.name }}</a>
     {% endfor %}
{% endif %}

当我直接转到路线“/ticket/attachment/{id}”时,会显示附件,但使用 ekko-lightbox 插件是我得到的(很多奇怪的字符 ��):

ekko-灯箱问题:

【问题讨论】:

    标签: symfony symfony4 vichuploaderbundle


    【解决方案1】:

    问题出在插件上。 我使用 lokeshdhakar / lightbox2 插件纠正了这个问题。

    【讨论】:

      猜你喜欢
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 2018-06-04
      • 2012-08-09
      相关资源
      最近更新 更多