Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
Get 'str' into Djano forms.FileField()

I'm uploading without a form. My user has a FileField if I'm uploading via <input type...> i have no problem. But this is not that handy for my purpose.

views.py

    def uploadaction2(request):
        f = forms.FileField() # this is my idea
        data = json.loads(request.body)
        # f.clean("data['data']") # error: file_name = data.name AttributeError: 'str' object has no attribute 'name'
        logger.error(type(data['data'])) #gives <class 'str'> and without the type the string that i want to save
        with open('newfile', 'w') as file:
            file.write(data['data'])
        request.user.file = file 
        request.user.save() # i get no error until this part

Error

Internal Server Error: ....  in pre_save
    if file and not file._committed:
AttributeError: '_io.TextIOWrapper' object has no attribute '_committed'

I think i have to convert the json string to a forms.FileField() by i've no idea how this could be done.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

    def uploadaction2(request):
        file = request.FILES.get('file') # set name to input
        request.user.file = file
        request.user.save()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda