0

I have a Django request doing some ML calculations. The request takes 3 files as input and generates several files as an output together with some temperature data calculations that I need, therefore I need to return content type = "multipart/form-data" as a Django Response.

If I try using rest_framework.response then I get: TypeError: keys must be str, int, float, bool or None, not tuple

from rest_framework.response import Response
return Response(thermal_response["data"], status=thermal_response["statusCode"])

If I try using JSONResponse I get: TypeError: Object of type ndarray is not JSON serializable

from django.http import JsonResponse
JsonResponse(thermal_response["data"], safe=False)
  • Did you already consider zipping those 3 files together and then send the .zip file via [`FileResponse`](https://docs.djangoproject.com/en/4.1/ref/request-response/#django.http.FileResponse) – Tarquinius May 25 '23 at 13:12
  • But how can I attach my temperature calculations data next to the zip in a FileResponse? – Bogi Kovacs May 25 '23 at 13:40
  • Ok, that I don't know. Maybe just add a 4th short textfile that contains the data and then ship it all together as mentioned .zip file? – Tarquinius May 25 '23 at 13:55

1 Answers1

0

You cannot implicity convert ndarray into Json. try tolist method, which allows you to convert an array to a list:

JsonResponse(thermal_response["data"].tolist(), safe=False)