I noticed that I with Django Rest Framework 3 no longer have to specify files=request.FILES when using a serializer in file uploads. According to the release notes, request.data now contains all the data. So, I simply removed files=request.FILES, and went from:
serializer = MediaSerializer(
theMedia,
data = postData,
files = request.FILES,
partial = True
)
to:
serializer = MediaSerializer(
theMedia,
data = postData,
partial = True
)
In my Django API app, I have a /media/ endpoint to which one can PUT the files photo and filename. When trying to PUT files with the change I made, the files never touch my custom storage. The header is correct (Content-Type: multipart/form-data), and it all worked fine in DRF 2.x.
I Noticed that I need to use the MultiPartParser in my view to be able to use the fileField, so now my view uses parser_classes = (JSONParser, MultiPartParser).
Here is the section of the serializer handeling the files:
class MediaSerializer(serializers.ModelSerializer):
photo = serializers.ImageField(
max_length = None,
required = False,
allow_empty_file = False)
filename = serializers.FileField(
max_length = None,
required = False,
allow_empty_file = False)
...
class Meta:
model = Media
fields = (
'photo',
'filename'
)
Maybe I should also mention that I have turned off UPLOADED_FILES_USE_URL in the settings.
My question is: What is it that I am missing out in DRF3 - Why does the uploaded files never touch my custom storage?