inputlogic / django-api-starter

Boilerplate for starting Django DRF / API projects
2 stars 0 forks source link

Add public upload and url generation for S3 files. #39

Closed eweisner1973 closed 4 years ago

eweisner1973 commented 4 years ago

This adds two basic methods for programmatically handling files hosted via S3 that will be publicly available. One is an upload method, the other is a URL generation method.

eweisner1973 commented 4 years ago

Curious if we could extend existing functions to handle this use-case. Also, these aren't being used by the Files app, so what is the use-case for them? Some doc-comments could help clear it up.

Curious if we could extend existing functions to handle this use-case. Also, these aren't being used by the Files app, so what is the use-case for them? Some doc-comments could help clear it up.

The use case is pretty rare. Basically trying to programmatically mimic what happens when a file is uploaded via a Django admin form using a field type that supports upload_to such as models.ImageField. When those types of fields are used on a form, behind the scenes we get the file uploaded to the appropriate S3 server, and a public URL that never expires rather than a generated URL that does expire. In my case, I had a website scraper downloading images, uploading them, and using the URL data in new records.

The logic may not belong here as it doesn't strictly require or use the File model.