[Answered ]-With FileField, opening file before inserting database

1👍

According to the docs its possible to create file object from memory. So you can do something like this:

def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)    
        serializer.is_valid(raise_exception=True)
            
        
        try:
         doc = fitz.open(“pdf”, request.data['drawing'])
         # or doc = fitz.open(“pdf”, request.data['drawing'].read())
        except;
         raise Exception("file is not valid pdf") 
        self.perform_create(serializer)
        

        

Leave a comment