djangodjango-formsdjango-formwizarddjango-storage

How can I use the Default File Storage(S3) to upload files with Django FormTools form wizard?


When uploading files, django-formtools Form Wizard, needs a place to temporarily store the until the user has completed all steps in the wizard.

The FormTools documentation shows an example of how to upload a file to a local folder on your server. The file_storage setting is required to upload files.

from django.core.files.storage import FileSystemStorage

class CustomWizardView(WizardView):
    file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'photos'))

We use Heroku and don't have access to local storage when uploading a file. We use django-storages and S3 to store all our files. I want to use django-storages to manage the upload process.

How can I just modify this view so that we use the default storage system to upload this file to a temporary location on S3?


Solution

  • This configuration will allow you to upload files directly to your django project's default storage backend. You can read about how it works in the documentation.

    from django.core.files.storage import DefaultStorage
    
    class CustomWizardView(WizardView):
        ...
        file_storage = DefaultStorage()