文件仍在从Symfony2应用程序的Android设备上下载

时间:2013-07-22 12:46:26

标签: android symfony version-control header download

在我的应用程序(Symfony2)中,我必须从UI向用户提供.vcs和.ics文件,以便在其设备日历中添加。我已经为iPhone做过了,但我的Android解决方案无效。它一直处于下载过程中,永远不会完成。

当我使用普通PHP执行相同的代码时,它可以工作并下载文件并集成到设备日历中。

普通PHP代码:

<?php
header("Content-Type: text/x-vCalendar");
header("Content-Disposition: attachment; filename=calendar.vcs");
?>
BEGIN:VCALENDAR
PRODID:-//AT Content Types//AT Event//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTAMP:20120801T133822Z
CREATED:20120801T042948Z
LAST-MODIFIED:20120801T043003Z
SUMMARY:My Event
DTSTART:20130719T000000Z
DTEND:20130720T000000Z
LOCATION:London
URL:https://www.myurl.com/
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR

Symfony2的代码:

public function getCalendarAction()
    {
        //$filename = "calendar_".date("Y_m_d_His").".vcs";
        $content = "BEGIN:VCALENDAR
PRODID:-//AT Content Types//AT Event//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTAMP:20120801T133822Z
CREATED:20120801T042948Z
LAST-MODIFIED:20120801T043003Z
SUMMARY:My Event
DTSTART:20130719T000000Z
DTEND:20130720T000000Z
LOCATION:London
URL:https://www.myurl.com/
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR";

        $headers = array('Content-Type'     => 'text/x-vCalendar',
            'cache-control'=>'no-store, no-cache, must-revalidate',
            'Content-Disposition' => 'attachment; filename="calendar.vcs"');

    return new Response($content, 200, $headers);    
}

enter image description here enter image description here

如果有人有问题的解决方案,请发帖。

1 个答案:

答案 0 :(得分:0)

问题现已解决。当我使用Valid Trusted SSL Certificate在Server上测试我的代码时,它会下载该文件并集成到Android设备日历中。