I'm using SQLAlchemy file along with SQLModel to manage files on AZURE_BLOB storage. This works fine, but all the files gets saved in the top-level of the Azure Storage container, regardless of the provided file name, path or any extra parameters I could find.
Is there a way to save files to a different folders on the target container?
For example, in the following, I would like to save file1.pdf to /general/, and file2.pdf to /backups/ of the same container.
# storage.py
driver = driver_cls(key=settings.storage_key, secret=settings.storage_secret)
container = driver.get_container(container_name=settings.storage_container)
StorageManager.add_storage(settings.storage_name, container)
StorageManager.set_default(settings.storage_name)
# models.py
class File(SQLModel, table=True):
id: int = Field(None, primary_key=True)
file: Union[File, UploadFile, None] = Field(None, sa_column=Column(FileField))
# controler.py
content = ...
file1 = File(content=content, filename=name, extra={'meta_data': meta_data})
file2 = File(content=content, filename=name, extra={'meta_data': meta_data})
with Session(engine) as session:
session.add(file1) # <- save this to <container>/general/
session.add(file2) # <- save this to <container>/backups/
sessionmit()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745094461a4610891.html
评论列表(0条)