Django bulk upload the files inside the zip

We want to bulk upload the files which is inside the zip, earlier we used to upload file by file. But the problem with that logic is, if the zip file is big by size. It's taking so much time to upload. So i need some solution to resolve this.

Old Logic:

archive = ZipFile(zipfile, 'r')
for filename in archive.namelist():
    name = filename.split('/')
    if name[-1] != '' and '__MACOSX' not in name:
        f = archive.open(filename)
        library = BulkUpload()
        library.organisation = organisation_id
        library.course = course_obj
        library.file_path.save(filename, ContentFile(f.read()))

I tried a new logic with bulk create, but there record is created in DB but file is not uploaded in the blob. When i check the DB, the file place only name is there.

archive = ZipFile(zipfile, 'r')    
for filename in archive.namelist():
    name = filename.split('/')
    if name[-1] != '' and '__MACOSX' not in name:
        request_obj.append(BulkUpload(
            organisation=data['organisation']['id'],
            course=course_obj,
            file_path=filename
        ))
BulkUpload.objects.bulk_create(request_obj)
Back to Top