Usage

To use these fields you must be using an AsyncUploadStorage storage class at either the global level, or field level. To setup globally see the Installation instructions.

To use at a field level create a storage class and pass it to the field:

storage = S3AsyncUploadStorage()

class MyModel(models.Model):
    file = AsyncFileField(storage=storage)
    image = AsyncImageField(storage=storage)

In addition to that two views need to be registered. GenerateUploadUrlView is used to generate a URL for the frontend to upload to (eg. a signed S3 URL). DownloadRedirectView is used to check a user has permissions on a file before redirecting to the download location (eg. a signed S3 URL). This is covered in the Installation guide.

Usage

All usages require a model - there’s currently no support for uploading files without the result being saved to an AsyncFileField or AsyncImageField.

The default template setup will work automatically for files in both django forms and Presto forms. Uploading is performed using the UploadWidget on the frontend (see UploadWidget.tsx).

For a deeper understanding of how django forms work see AsyncFileField and AsyncFileInput.

async_uploads.rest_framework integration requires you to use the async_uploads.rest_framework fields alliance_platform.storage.async_uploads.rest_framework.AsyncFileField or alliance_platform.storage.async_uploads.rest_framework.AsyncFileField. See Serializer Fields for how to set this as a default.

Intermediate files are stored in the alliance_platform.storage.async_uploads.models.AsyncTempFile table. This should be periodically cleaned up by running the cleanup_async_temp_files command.