Added first set of api calls including dropbox upload
This commit is contained in:
parent
aac6d7c827
commit
31899ebd64
@ -219,3 +219,4 @@ LOGGING = {
|
|||||||
# increase the maximum upload size of files
|
# increase the maximum upload size of files
|
||||||
DATA_UPLOAD_MAX_MEMORY_SIZE = 104857600
|
DATA_UPLOAD_MAX_MEMORY_SIZE = 104857600
|
||||||
|
|
||||||
|
DROPBOX_OAUTH2_ACCESS_TOKEN = 'sl.AmBKKaIkaH0ZKuk5i60EbN8dIspDugFK2k4ixfMkr3BZ7ZJ0yF5YAj-69mWKO-G_K-ctk_Ai4a6BeOXEZ_kZH4waUUlPhnV3QBe4QfGYN5PQcs-9SwQ5BWQfeQSKw9jkybbV9mjOdQ4'
|
||||||
@ -18,11 +18,14 @@ from django.contrib import admin
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
from app_be.views.rest_api import TestApiClass
|
from app_be.views.rest_api import TestApiClass, ImageEndpoint
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
url(r'^test/', TestApiClass.test_api),
|
url(r'^test/', TestApiClass.test_api),
|
||||||
|
url(r'^image/get$', ImageEndpoint.image_api_get_all),
|
||||||
|
url(r'^image/get/(?P<id>[0-9]+)$', ImageEndpoint.image_api_get_single),
|
||||||
|
url(r'^image/post$', ImageEndpoint.image_api_post)
|
||||||
]
|
]
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
|
import base64
|
||||||
|
import dropbox
|
||||||
|
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from rest_framework.decorators import api_view
|
from rest_framework.decorators import api_view
|
||||||
|
|
||||||
@ -13,3 +18,26 @@ class TestApiClass:
|
|||||||
def test_api(request):
|
def test_api(request):
|
||||||
logger.debug('Test api call: {}'.format(request))
|
logger.debug('Test api call: {}'.format(request))
|
||||||
return JsonResponse({'Result': 'success'}, safe=False)
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user