Skip to content

Commit

Permalink
fix: media endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
marschhuynh authored and nicolaiarocci committed Apr 5, 2018
1 parent 0f0d047 commit ffdeb14
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions eve/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,31 +210,29 @@ def media_endpoint(_id):
else:
file_ = app.media.get(_id)
size = file_.length
byte1, byte2 = 0, None

m = re.search('(\d+)-(\d*)', range_header)
g = m.groups()

if g[0]:
byte1 = int(g[0])
if g[1]:
byte2 = int(g[1])

length = size - byte1
if byte2 is not None:
length = byte2 - byte1 + 1
try:
m = re.search('(\d+)-(\d*)', range_header)
begin, end = m.groups()
begin = int(begin)
end = int(end)
except:
begin, end = 0, None

length = size - begin
if end is not None:
length = end - begin + 1

data = None
file_.seek(byte1)
file_.seek(begin)
data = file_.read(length)

headers = {
'Last-Modified': date_to_rfc1123(file_.upload_date),
'Content-Length': file_.length,
'Accept-Ranges': 'bytes',
'Content-Range': 'bytes {0}-{1}/{2}'.format(
byte1,
byte1 + length - 1,
begin,
begin + length - 1,
size
),
}
Expand Down

0 comments on commit ffdeb14

Please sign in to comment.