Package: django-async-image-upload
Django-async-image-uploadAsync image upload using presigned url for Django.This module provide async processing capability using cloud architecture.
With this you can decouple code from Django api server and easily extend image processing capability.There are already plenty of good thumbnail packages such assorl-thumbnail,django-imagekit.
However most of the packages process image on django server. Some are partially asynchrounous with celery and other technique, but server still needs to recieve files from client to proecess them.Using S3(and others storages in the futures) presigned-url feature, client can directly uploads to S3 without involving backend server.
Once image is uploaded, api server gets callback once image processing in finished elsewhere(serverless function in this case.Current version only provide asynchronous upload with lambda function. There are a lot more to do with this module.Unittest and github actionMultiple presigned url creationLambda in VPC if function needs to communicate resources in VPC. NAT support for callbackMonitoring and alertDecouple S3 Event trigger with lambda with SNS or EventBridgeHookup aws rekognition or other vision service for image metadataGCP signed url and cloud functionAzure shared Access Signature(SAS) with Azure functionSupport for Django 2.X (Jsonfield)Architecture (AWS version)Client request forpresigned urlfor image upload.Server generatePresigned URLfor upload.Server returns presigned url credential.Client uploads files in multipart/form with credential.As soon as file is created on s3 bucket, lambda is triggered for image processing.Lambda calls api server for callback for success or failure.Refer tosequence diagramfor more detail.RequirementsBecause this module supports native django json fields,Django 3.1 and upPython 3.6 and upDB: MariaDB 10.2.7+, MySQL 5.7.8+, Oracle, PostgreSQL, and SQLitepython packagesdjangorestframeworkdrf-yasgboto3InstructionCloud moduleYou need to deploy cloud module(storage and serverless function) first.
I provided SAM tempalte to automate deployment. Refer to following page for detailed instruction.Cloud moduleDjango API ModuleInstall Django-async-image-upload::pip install django-async-image-uploadAdd it to your INSTALLED_APPS::INSTALLED_APPS = (

    'django_async_image_upload.apps.AsyncImageUploadAppConfig',

)Add Django-async-image-upload's URL patterns::from django_async_image_upload import urls as django_async_image_upload_urls

urlpatterns = [
    url(r'^', include(django_async_image_upload_urls)),
]SettingsAvailable settings are:ASYNC_IMAGE_UPLOAD_BUCKETname of bucket where presigned url is generateddefault: NoneASYNC_IMAGE_UPLOAD_TEMPORARY_IMAGE_PATHfolder path where image is uploaded using presigned urldefault: "temp/"ASYNC_IMAGE_UPLOAD_PRESIGNED_URL_EXPIRATIONPresigned url expiration in seconddefault: 1000ASYNC_IMAGE_UPLOAD_PRESIGNED_URL_REUSE_WINDOWTime in second where you can reuse already generated presigned urldefault: 30ASYNC_IMAGE_UPLOAD_PRESIGNED_URL_CONTENT_LENGTHMax size of image in bytedefault: 10485760 # 10MiBPROCESSED_IMAGE_MODELImage model that will be created when success callback is issued.default: "ProcessedImage"AWS_ACCESS_KEY_IDandAWS_ACCESS_KEY_SECRETAssuming you are already using Boto3, you need to set following AWS credentialsCreate presigned urlPOST to/async_image/presignedurl/to generate presignedurl credential.SwaggerFor more information regarding api, you can access swagger on http:///async_image/docs/swagger?format=openapiUpload image file to bucketClient can use multipart/form upload to given url and fields in credential in with image file to upload to s3 bucket.Order of the key matters, I recommend you to send in order of "key, acl, x-amz-meta-id... file".CheckupBecause of the nature of the async operation, you won't be able to find out the result of the upload.
You can use following options.Long polling - GET request to/async_image/presignedurl/<uuid>for completion.Open connection with sever using technics such as websocket, graphql.Assume operation is successful workaround it.It's your choice.Extra noteIf you are deploying on EC2, your EC2 should have appropriate IAM credential or EC2 role withs3:putOjectpermission on particular bucket.Running TestsTBDDevelopment commandsCreditsTools used in rendering this package:Cookiecuttercookiecutter-djangopackageHistory0.1.0 (2021-06-07)
++++++++++++++++++First release on PyPI.