Uploading large files with Python/Django

后端 未结 3 669
面向向阳花
面向向阳花 2020-12-02 23:04

I am wondering if there are any ramifications in uploading files that are roughly 4GB in size through a web app using Django/Python? I remember in the past streaming uploads

3条回答
  •  我在风中等你
    2020-12-02 23:50

    The last answer covers it. We routinely upload 2.5mb+ (but usually not 4gb)

    adamnish link is correct, see this snippet (from his link to django docs) regarding writing the file to disk, instead of having it in memory first:

    def handle_uploaded_file(f):
        with open('some/file/name.txt', 'wb+') as destination:
            for chunk in f.chunks():
                destination.write(chunk)
    

    More info on the "chunks" call: https://docs.djangoproject.com/en/dev/ref/files/uploads/#django.core.files.uploadedfile.UploadedFile.chunks

    Page includes how to set "chunk" size, etc.

提交回复
热议问题