Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import json
  2. from rest_framework.decorators import api_view
  3. from rest_framework.response import Response
  4.  
  5.  
  6. @api_view(['POST'])
  7. def foo(request):
  8. attributes = json.loads(request.data['attributes']) # will be a 'dict'
  9. xsd_file = request.data['xsd_file'] # "InMemoryUploadFile" instance
  10. Iccs_file = request.data['Iccs_file'] # "InMemoryUploadFile" instance
  11. return Response("some response")
  12.  
  13. class multipleFileUpload(APIView):
  14.  
  15. def post(self, request):
  16. """
  17.  
  18. :param request:
  19. :return:
  20. """
  21. try:
  22. #this will read attributes other than file
  23. str_value = request.POST["attributes"]
  24. print(str_value)
  25.  
  26. #check if any file send in request if yes read all files one by one
  27. if len(request.FILES) != 0:
  28. for key in request.FILES:
  29. file_obj = request.FILES[key]
  30. print(file_obj.read()) #getting contents of the file in bytes
  31. return JsonResponse({"res": "got files"})
  32. except Exception as e:
  33. print(str(e))
  34. return JsonResponse({"res": "error"})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement