I am new to Django and doing a small project where the user logs into a Django powered website and can then upload some images. These images will need to have some preprocessing on them before it can be used by the remote services. What I would like to do is perform the preprocessing on the client side and I have some python code that does it. However, I am not sure how I can setup Django so that the user can grant it permissions to run some code locally (and generate some files in the temporary directory).
So, for example, one of my view is as follows:
class UploadImageView(APIView):
permission_classes = (IsAuthenticated, )
authentication_classes = (JSONWebTokenAuthentication, )
# Create your views here.
def post(self, request):
image = request.FILES['image']
study = int(request.data.get('study').strip())
if image is None:
return Response(status=status.HTTP_400_BAD_REQUEST)
# Check study ID and Image type exists
s = StudyModel.objects.filter(pk=study).first()
if s is None:
return Response(status=status.HTTP_412_PRECONDITION_FAILED)
try:
_ = ImageModel.objects.create(path=image, study=s)
except:
return Response(status=status.HTTP_417_EXPECTATION_FAILED)
return Response(status=status.HTTP_200_OK)
Now currently, the user needs to run some code locally manually to generate this transformed image and then call the ReST API to upload it. What would be nice is the user selects the raw image, some code transforms it locally and then uploads the transformed image.