I generally suggest using files as context managers, so you don't have to close them after. You could do something like this:
```python
if int(content_range['start']) == 0:
    mode = "wb+"
else:
    mode = "ab+"
with open(temp_filepath, mode) as temp_file:
    for chunk in request.FILES['course-data'].chunks():
        temp_file.write(chunk)