amol- / depot

Toolkit for storing files and attachments in web applications
MIT License
161 stars 41 forks source link

UploadedFileField is not accept multiple files #71

Closed maz1987in closed 2 years ago

maz1987in commented 2 years ago

I would like to upload multiple files to the database files

amol- commented 2 years ago

UploadedFileField is for a single file (as it's a reference to a file), but you can subclass it and upload multiple files like what UploadedImageWithThumb does ( https://github.com/amol-/depot/blob/master/depot/fields/specialized/image.py )

maz1987in commented 2 years ago

I am new to python. so sorry is the question if seen non-sense: in SQLAlchemy field

photo = Column(UploadedFileField(upload_storage ='media'))

could I change upload_storage base on another field?

like:

storage = Column(String(length=255))
photo = Column(UploadedFileField(upload_storage =storage))

in other words, Could I change the upload_storage in the fly?

amol- commented 2 years ago

I think you should be able to achieve that by setting the depot_name in a UploadedFile you provide for the column

class Document(DeclarativeBase):
    ...
    storage = Column(String(length=255))
    photo = Column(UploadedFileField)

doc = Document()
doc.photo = UploadedFile(file_content, depot_name=doc.storage)
maz1987in commented 2 years ago

Thank you it's working

what about thumbnail filter could also be changed?

maz1987in commented 2 years ago

@amol- Thanks for your help I have been able to do amazing work with your wonderful project