Добавить заголовок Content-Disposition к drf-yasg
У меня есть django APIView с документацией swagger с использованием drf-yasg. Каждый раз, когда я делаю пост-запрос к API, я получаю этот ответ об ошибке
{
"detail": "Missing filename. Request should include a Content-Disposition header with a filename parameter."
}
Когда я добавляю заголовок Content-Disposition к запросу postman, я получаю правильные ответы. Content-Disposition: attachment; filename=<insert-your-file-name>
Мой вопрос в том, как мне добавить Content-Disposition в декоратор drf-yasg swagger_auto_schema
, если это возможно.
Вот как выглядит мой APIView
class ReceiptsUploadView(APIView):
parser_classes = (FileUploadParser, MultiPartParser)
params = [openapi.Parameter("file", openapi.IN_FORM, type=openapi.TYPE_FILE)]
@swagger_auto_schema(operation_description="file", manual_parameters=params)
def post(self, request):
file_obj = request.FILES.get("file")
if file_obj:
fs = FileSystemStorage()
file = fs.save(file_obj.name, file_obj)
file_url = os.path.join(settings.BASE_DIR, fs.url(file)[1:])
receipt_blocks = Receipt(blocks=extraction_data(file_url))
receipt_blocks.save()
return Response(
extraction_data(file_url),
status=status.HTTP_200_OK,
)
else:
return Response(
{"error": "file not selected"}, status=status.HTTP_400_BAD_REQUEST
)