here is what I have:
I have got a route where I call a service to rotate a given image.
/**
* @Route("/media/rotate/{id}", name="rotate_image")
*
* @ParamConverter(name="media", class="RA\MediaBundle\Entity\Media")
*
* @param Media $media
*
* @return RedirectResponse
*/
public function rotateImage(Media $media)
{
$this->get('ra.image.rotator.service')->rotateImage($media, 90);
// do the redirect
}
and here is what I would like to do:
Do a redirect on the route I came from (with the help of referer). This does work, but after the redirect the rotated image isn't displayed, because it is cached.
So I thought setting "Last-Modified" in the header to the current DateTime would force the browser to reload the image. I tried to do it the following way:
if ($referer = $request->headers->get('referer')) {
$response = new RedirectResponse($referer);
$response->setLastModified(new \DateTime());
return $response;
}
But unfortunately "Last-Modified" is only set in the header of the rotate_image route, not in the one I got redirected to.
Any idea how to solve this issue?
Edit:
I have "solved" my issue by just adding a version parameter to the media urls like this:
return $mediaUrl . '?v=' . md5($media->getUpdatedAt()->format('Y-m-d H:i:s'));
So after rotating the image I'm updating the media entity so that the version will change and the "new" image will be shown.