'DRF upload extracted zip files
I'm going to upload some files through my DRF API. This API receives a .zip file that has some .xlsx files in. I extract its content in the API view. Then I send this data to the serializer, But I get this error:
[
{
"file_name": [
"The submitted data was not a file. Check the encoding type on the form."
]
}
]
This is how I'm extracting my .zip file before passing data to the serializer:
def _get_serializer_initial_data(self):
with ZipFile(self.request.FILES.get('file_name')) as input_zip:
return [
{
'file_name': input_zip.open(_input_excel)
}
for _input_excel in input_zip.infolist()
]
Then I send data to the serializer this way:
initial_data = self._get_serializer_initial_data()
serializer = self.get_serializer(data=initial_data, many=True)
I checked the extracted files type in the serializer class and it's ZipExtFile, which seems to be unacceptable by DRF.
Any help would be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
