Categories
coding tips

django REST framework downloading binary files

When returning a Response from django REST API that contains a binary file, you may encounter an issue:

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte  in position 11: invalid start byte

Categories
coding tips

Handling files upload in django & python 3 without Forms

Sometimes you need to accept a file from a user, and you don’t want to use django Forms. The details come down to how many files you need to accept and do you know the names of the files.

If the file is from your app (or frontend) and you expect it you’ll know the file name, because you named it. But if it is a user selected file the name will be unknown.