octue / django-gcp

Everything required to run Django on GCP (storage, pubsub events, tasks, logging, errors)
Other
21 stars 3 forks source link

How to add validators to BlobField #61

Open morphogencc opened 8 months ago

morphogencc commented 8 months ago

Support request

About me

Hello! I'm using django to make the backend for science museum installations. I use django to manage data, allow museum staff to make updates to multimedia on the museum floor, and ultimately provide the backend for visitor-facing multimedia experiences.

Request

I'm trying to identify how I can add validators to BlobField for GCP storage. I'd love to be able to validate file types and, if the underlying data is multimedia, check image or video dimensions. The documentation doesn't make it clear how I could control what type of Blobs are uploaded.

Supporting Octue

Octue is an Open-Source Software organisation helping you and many others to fight climate change. Providing support for your issues costs us c. 500GBP/day. Might your organisation be in a position to help sponsor this issue?

thclark commented 8 months ago

Hi @morphogencc - welcome and thnaks for using dajngo-gcp. I love that the science museum is getting value out of it!

I think it should be possible to achieve what you're looking for by restricting the accept attribute on the file upload widget, and thus rather than creating a validation error, simply prevent upload of file types.

I looked into this when building, and as I recollect, it was possible.

More tricky is extraction of metadata from the files, particularly checking size information and the like. If you need to open and process file contents to get that data, we'd need to think hard about the pattern of how to do that without filling your server with video processing code! This might be a good use case for a background worker task or lambda function that adds metadata to the object itself.

A couple of other questions:

If you're still opening to sponsor us closing the issue, may I suggest you book a quick meeting on calendly (we'd only need 30 minutes) and we'll have a look together.

Best,

Tom