Commit 9a6af644 authored by eduardmisa's avatar eduardmisa

file download for get

parent 5418bf4e
......@@ -43,9 +43,14 @@ class Helper:
def _request_method(self, request, final_endpoint, headers):
if request.method == 'GET':
req = requests.get(final_endpoint, headers=headers)
return self._response_data(req.json(),
req.status_code,
self._headers)
if req.headers.get('content-type') == 'application/json':
return self._response_data(req.json(),
req.status_code,
req.headers)
else:
return req
elif request.method == 'POST':
data = copy.deepcopy(request.data)
......
from rest_framework.views import APIView
from rest_framework.response import Response
from .utils import Helper
from django.conf import settings
from django.http import FileResponse
class APIGatewayList(APIView):
......@@ -9,6 +10,19 @@ class APIGatewayList(APIView):
service = kwargs.get('service')
endpoint_url = kwargs.get('endpoint_url')
api = Helper().get_endpoint(request, service, endpoint_url)
if str(type(api)) == "<class 'requests.models.Response'>":
# varifile = f"{settings.BASE_DIR}/test.xlsx"
# filedesciptor = open(varifile, 'wb')
# filedesciptor.write(api.content)
# filedesciptor.close()
# filer = open(varifile, 'rb')
return FileResponse(api, as_attachment=True)
return Response(api['data'],
status=api['status_code'],
headers=api['headers'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment