
Cannot play videos served by rails 4
Hello fellow developers,
Our system stores short videos in the database and serves them as files back to the browser.
Some browsers, i.e. Chrome/Firefox on the Mac or IE/Chrome/Firefox on Windows play the
videos normally. However, the Safari browser on Mac, as well as Safari/Chrome on iOS,
and Chrome/Firefox on Android complain that "File could not be played".
Here is one of the conversations between the browser and the server that lead to such
message on a development machine:
=> [Browser]
GET /attachments/523/b79694dcb032724b8660dd0728242e98.mp4 HTTP/1.1
Host: 0.0.0.0:3002
Cookie: [lots of cookie data]
X-Playback-Session-Id: 8CAA5FDB-F6D6-4CBA-AAAC-5485AEAC48CD
Range: bytes=0-1
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.77.4 (KHTML, like Gecko) Version/7.0.5 Safari/537.77.4
Referer: http://0.0.0.0:3002/attachments/523/movie_player
Accept-Encoding: identity
Connection: keep-alive
=> [Server]
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Ua-Compatible: chrome=1
Content-Disposition: attachment; filename="02e9b00c9d65091b915327c3af30031a.mp4"
Content-Transfer-Encoding: binary
Content-Type: video/mp4
Cache-Control: private
X-Meta-Request-Version: 0.3.0
X-Request-Id: 120058eb-0459-4e06-b108-9e29a5afb735
X-Runtime: 0.034226
Server: WEBrick/1.3.1 (Ruby/2.1.0/2013-12-25)
Date: Sun, 06 Jul 2014 23:29:49 GMT
Content-Length: 304829
Connection: Keep-Alive
Set-Cookie: [complete cookie data]
[~300K of binary file data]
===========================================================
For whatever reason the browser rejects the file and issues a different request,
acting on behalf of the AppleCoreMedia:
===========================================================
=> [Browser]
GET /attachments/523/b79694dcb032724b8660dd0728242e98.mp4 HTTP/1.1
Host: 0.0.0.0:3002
Cookie: [complete cookie data]
Range: bytes=0-1
Accept: */*
User-Agent: AppleCoreMedia/1.0.0.13E28 (Macintosh; U; Intel Mac OS X 10_9_4; en_us)
Accept-Encoding: identity
Connection: keep-alive
=> [Server]
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Ua-Compatible: chrome=1
Content-Disposition: attachment; filename="02e9b00c9d65091b915327c3af30031a.mp4"
Content-Transfer-Encoding: binary
Content-Type: video/mp4
Cache-Control: private
X-Meta-Request-Version: 0.3.0
X-Request-Id: 376be02f-b8a4-4f3a-bba3-52b80f8c18c9
X-Runtime: 0.029857
Server: WEBrick/1.3.1 (Ruby/2.1.0/2013-12-25)
Date: Sun, 06 Jul 2014 23:29:49 GMT
Content-Length: 304829
Connection: Keep-Alive
Set-Cookie: [complete cookie data]
[~300K of binary data]
=================================================
The file is again rejected, and the new request comes from
QuickTime, this time with a significantly reduced session cookie:
=================================================
=> [Browser]
GET /attachments/523/b79694dcb032724b8660dd0728242e98.mp4 HTTP/1.1
Host: 0.0.0.0:3002
Accept: */*
User-Agent: QuickTime/7.7.3 (qtver=7.7.3;cpu=IA32;os=Mac 10.9.4)
Connection: close
Cookie: ace.settings=%7B%22sidebar-collapsed%22%3A-1%7D;
=================================================
Because the cookie no longer holds authentication credentials,
The server responds in the appropriate way:
=================================================
=> [Server]
HTTP/1.1 302 Found
[snip]
Location: http://0.0.0.0:3002/accounts/sign_in
Does anyone know what is preventing the player from playing the video?
Is there anything wrong with this kind of server setup?
=======================================================
Thank you very much for your attention,
Best regards,
Konstantin Semenov.