Send images in Json request along with other Fields

18 views
Skip to first unread message

Softtar

unread,
Oct 18, 2020, 7:24:02 AM10/18/20
to Django REST framework

Content-Type: multipart/form-data; boundary=xxBOUNDARYxx


--xxBOUNDARYxx

Content-Type: application/json

Content-Disposition: form-data; name="Details";


{

"Name": "cust",

"FatherName": "Father Name",



"Type": "Flate",

"CNIC": "022543261544",

"Mobile": "03245432615",

"Phone": "0425432615",

"Address1": "Street 1 ",

"City": "Lahore"

}

--xxBOUNDARYxx

Content-Disposition: form-data; name="PropertyDocImage"; filename="property_image.png"

Content-Type: image/png


{image file data bytes}

--xxBOUNDARYxx

Content-Disposition: form-data; name="CNICFrontImage"; filename="CNICFront_image.png"

Content-Type: image/png


{image file data bytes}

--xxBOUNDARYxx

Content-Disposition: form-data; name="CNICBackImage";

filename="CNICBack _image.png"

Content-Type: image/png


{image file data bytes}

--xxBOUNDARYxx

Content-Disposition: form-data; name="NeighborBillImage"; filename="NeighorBill_image.png"

Content-Type: image/png


I want to send images like above mentioned but it's not working for me.

Here I am trying to do

class ApplicationAPI(generics.GenericAPIView):
serializer_class = ApplicationSerializer
parser_classes = (JSONParser, MultiPartParser, FormParser)
def post(self, request):
serializer = self.get_serializer(data=request.data)
if serializer.is_valid(raise_exception=True):
application = serializer.save()
if application:
return Response({
"application": AppsSerializer(application, context=self.get_serializer_context()).data,
"status": 1,
"Message": "Success, continue to application setup",

})
return Response(
{
"status": 0,
"Message": "could not create record, try again."

}

)


Please help me in this 

Reply all
Reply to author
Forward
0 new messages