Added first set of api calls including dropbox upload
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import logging
|
||||
import json
|
||||
import base64
|
||||
import dropbox
|
||||
|
||||
from django.http import JsonResponse
|
||||
from django.http import HttpRequest
|
||||
from django.conf import settings
|
||||
|
||||
from rest_framework.decorators import api_view
|
||||
|
||||
@@ -13,3 +18,26 @@ class TestApiClass:
|
||||
def test_api(request):
|
||||
logger.debug('Test api call: {}'.format(request))
|
||||
return JsonResponse({'Result': 'success'}, safe=False)
|
||||
|
||||
|
||||
class ImageEndpoint:
|
||||
@staticmethod
|
||||
@api_view(['GET'])
|
||||
def image_api_get_all(request):
|
||||
logger.debug('Image GET all call: {}'.format(request))
|
||||
return JsonResponse({'Result': 'success1'}, safe=False)
|
||||
|
||||
@staticmethod
|
||||
@api_view(['GET'])
|
||||
def image_api_get_single(request, id):
|
||||
logger.debug('Image GET single call: {}'.format(request))
|
||||
return JsonResponse({'Result': 'success1', 'id': id}, safe=False)
|
||||
|
||||
@staticmethod
|
||||
@api_view(['POST'])
|
||||
def image_api_post(request: HttpRequest):
|
||||
logger.debug('Image POST call: {}'.format(request))
|
||||
data = json.loads(request.body.decode('utf-8'))
|
||||
dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_ACCESS_TOKEN)
|
||||
dbx.files_upload(base64.b64decode(data['image_data']),'/Apps/AIC Federated Storage Infrastructure/test_image_1.jpg')
|
||||
return JsonResponse({'Result': 'success2', 'received file': data['filename']}, safe=False)
|
||||
|
||||
Reference in New Issue
Block a user