Django add pdf to a request value

in the following request I receive a total of 10 pdfs which I must combine in one document once this is done I have to upload it to the client model which stores the files in aws s3, once I pass the file with all the pdfs together it gives me the following error

{
    "error": true,
    "message": {
        "documents": [
            "The submitted data was not a file. Check the encoding type on the form."
        ]
    }
}

this is mi code

 merger = PdfFileMerger()
                    for x in request.FILES:
                        print(request.FILES[x])
                        merger.append(request.FILES[x])
                    merger.write(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'media/' + str(getUser.id) + '.pdf'))
                    merger.close()
                    
                    pdf = open(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'media/' + str(getUser.id) + '.pdf'), 'rb')
                    # set the client Data
                    clientData = {
                        'type_client': request.data['type_client'],
                        'type_identity': request.data['type_identity'],
                        'document_number': request.data['document_number'],
                        'first_name': request.data['first_name'] if 'first_name' in request.data else None,
                        'last_name': request.data['last_name'] if 'last_name' in request.data else None,
                        'social_reason': request.data['social_reason'] if 'social_reason' in request.data else None,
                        'address': request.data['address'],
                        'city': request.data['city'],
                        'email': request.data['email'],
                        'phone_number': request.data['phone_number'],
                        'ciiu': request.data['ciiu'],
                        'broker': request.data['broker'],
                        'user': getUser.id,
                        'documents': pdf,
                        'status': 0,
                        'income': request.data['income'],
                        'entered_by': request.user.id
                    }
                    # Create a new client
                    client = ClientSerializer(data=clientData)

this is my model

from django.db import models

# Relations
from apps.misc.models import City, TypeIdentity, TypeCLient, CIIU
from apps.clients.api.models.broker.index import Broker
from apps.authentication.api.models.user.index import User


class Client(models.Model):
    id              = models.CharField(max_length=255, unique=True,primary_key=True, editable=False)
    type_client     = models.ForeignKey(TypeCLient, on_delete=models.CASCADE, blank=True)
    type_identity   = models.ForeignKey(TypeIdentity, on_delete=models.CASCADE, blank=True)
    document_number = models.CharField(max_length=255, blank=True, unique=True)
    first_name      = models.CharField(max_length=255, blank=True, null=True)
    last_name       = models.CharField(max_length=255, blank=True, null=True)
    social_reason   = models.CharField(max_length=255, blank=True, null=True)
    city            = models.ForeignKey(City, on_delete=models.CASCADE, blank=True)
    address         = models.CharField(max_length=255, blank=True)
    email           = models.CharField(max_length=255, blank=True, unique=True)
    phone_number    = models.CharField(max_length=255, blank=True, unique=True)
    ciiu            = models.ForeignKey(CIIU, on_delete=models.CASCADE, blank=True)
    broker          = models.ForeignKey(Broker, on_delete=models.CASCADE, blank=True)
    user            = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)
    documents       = models.FileField(upload_to='documents/')
    income          = models.SmallIntegerField(blank=True, default=0)
    entered_by      = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, related_name='entered_by')
    state           = models.BooleanField(default=False)
    created_at      = models.DateTimeField(auto_now_add=True)
    updated_at      = models.DateTimeField(null=True, default=None)

    class Meta:
        db_table = 'clients'
        verbose_name = 'clients'
        verbose_name_plural = 'clients'
        ordering = ['created_at']

as you can see in the documents property of the clientData dict I assign the combined pdf previously, is there any way to solve this?

Back to Top