Sending Image from React-Native app to Django Models

79 Views Asked by At

I am building a react-native app with a Django backend. I am trying to send a user input image to Django to be saved as an ImageField in Django Models without using REST-FRAMEWORK. How can I do that?

1

There are 1 best solutions below

3
Barun Bhattacharjee On

Suppose you have a model called Image then you can save the image using the following way.

from django.http import HttpResponse
from django.core.exceptions import PermissionDenied


def saveImage(request):

    if request.POST:
        if 'image' not in request.POST:
            return HttpResponse('Bad POST Parameters. Please use "image" key')

        image = request.POST['image']

        Image.objects.create(image=image)
        
        return HttpResponse('Image successfully saved')      
    else:
        raise PermissionDenied