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

262
Visualizações
multiple files upload - django

I'm uploading multiple files to django and when I was saved files only it saved one. Execution example:

------------------------------------ start files ------------------------
<MultiValueDict: {u'patientFiles': [<InMemoryUploadedFile: Registro VFC JOSE DE LA CRUZ_16_03_2015.txt (text/plain)>, <InMemoryUploadedFile: JDTD datos vfc_27_04_2015.txt (text/plain)>]}>
    *-1-*Registro VFC JOSE DE LA CRUZ_16_03_2015.txt
    *-2-*<django.core.files.storage.FileSystemStorage object at 0xaf731aac>
    *-1-*JDTD datos vfc_27_04_2015.txt
    *-2-*<django.core.files.storage.FileSystemStorage object at 0xaf731e4c>
    *-3-*JDTD datos vfc_27_04_2015.txt
    *-4-*JDTD%20datos%20vfc_27_04_2015.txt
    --------------------------------------------------------------------------

How you can see it goes to 3 and 4 points one time and it doesn't save first file. Have you any idea about?

Thanks and next are code.

This is django-server code:

def startFiles(self,request):
    print colored("----------------- start files -----------------------",'blue')
    print colored(request.FILES,'blue')
    for afile in request.FILES.getlist('patientFiles'):
        myfile = afile
        print colored("*-1-*" + str(myfile),'blue')
        fs = FileSystemStorage()
        print colored("*-2-*" + str(fs),'blue')
        filename = fs.save(myfile.name, myfile)
        print colored("*-3-*" + str(filename),'blue')
        uploaded_file_url = fs.url(filename)
        print colored("*-4-*" + str(uploaded_file_url),'blue')
    print colored("--------------------------------------------------------------------------------",'blue')

this is HTML code:

<form id="SuPF" class="form-group" enctype="multipart/form-data" action="/formSingupPatient" method="POST">
    <input type="file" multiple="true" name="patientFiles">
    <button type="submit" id="SubmitForm" class="btn btn-default">Submit</button>
</form>
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

finaly I used python's files API to save many files. I change startFiles code with:

def startFiles(self,request):
print colored("----------------- start files -----------------------",'blue')
print colored(request.FILES,'blue')
for afile in request.FILES.getlist('patientFiles'):
    myfile = afile
    print colored("*-1-*" + str(myfile),'blue')
    fs = FileSystemStorage()
    print colored("*-2-*" + str(fs),'blue')
    filename = settings.MEDIA_ROOT + "/" + myfile.name
    f = open(filename,'w')
    print colored(f,'blue')
    f.write(myfile.read())
    f.close()
print colored("--------------------------------------------------------------------------------",'blue')

I used buffer to create a file and save file.

settings.MEDIA_ROOT is a system path where save files.

I hope help you on future.

over 4 years ago · Santiago Trujillo Relatório

0

To upload to model and to save in file system as well I used this

for d in request.FILES.getlist("asd"):
        def process(f):
            with open('./media/file_' + x.name, 'wb+') as destination:
                for chunks in f.chunks():
                    destination.write(chunks)
                    obj = Details()
                    obj.xxx= './media/f_' + x.name
                    obj.type = type
                    obj.save()
        process(d)
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