Skip to content

Commit

Permalink
Merge pull request #1332 from Amsterdam-Music-Lab/bugfix/fetch-filename
Browse files Browse the repository at this point in the history
Fix section retrieval during development
  • Loading branch information
BeritJanssen authored Nov 5, 2024
2 parents 10e927a + 88ad361 commit 99a8db4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions backend/section/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ def get_section(request: HttpRequest, section_id: int) -> Section:
# Option 2: stream file through Django
# Advantage: keeps url secure, correct play_count value
# Disadvantage: potential high server load

filename = join(settings.BASE_DIR, settings.MEDIA_ROOT, str(section.filename))
filename = str(section.filename)
if filename.startswith("/"):
# remove initial slash in filename, as otherwise os.path.join considers it an absolute path
filename = filename[1:]
filepath = join(settings.MEDIA_ROOT, filename)

# Uncomment to only use example file in development
# if settings.DEBUG:
# filename = settings.BASE_DIR + "/upload/example.mp3"

response = FileResponse(open(filename, 'rb'))
response = FileResponse(open(filepath, "rb"))

# Header is required to make seeking work in Chrome
response['Accept-Ranges'] = 'bytes'
Expand Down

0 comments on commit 99a8db4

Please sign in to comment.