What is the correct way to just route a front-end request (that used to work) through a gateway to a service (that used to work). (Even now, if I send the front-end request strait to the service everything still works, so it it just my gateway view that is not handling and forwarding the request properly)
My front-end used to post images with user posts to my back-end just fine. But I have implemented a gateway and now the only thing I am still struggling with is just forwarding a file that the user posts to the required service:
All my gateways just json.dumps()
the incoming request data and moves on, but with the image I get an error along the lines of: TypeError: Object of type InMemoryUploadedFile is not JSON serializable
- which I perfectly understand, but what is the correct way to send the image along to the service?
My gateway view:
class DailyReportImages(APIView):
def post(self, request, *args, **kwargs):
url = INSERT_DAILY_REPORT_IMAGE
res = requests.post(url, headers=request.headers, data=json.dumps(request.data), files=request.files)
return Response(res.json(), res.status_code)
This is what I have for now after days of searching, and at least it reaches the backend now, but it still gives almost every error in the book depending on how I tweak it...
res = requests.post(url, headers=request.headers, data={"name": "test", "report": "myreport"}, files={'Screenshot from 2020-01-06 19-04-33.png': request.FILES["image"]})
For instance service complains that the name/report
values are empty...