sqlmodel - Dynamically set path in target cointaier when saving files using SQLAlchemy-files on Azure storage - Stack Overflow

I'm using SQLAlchemy file along with SQLModel to manage files on AZURE_BLOB storage. This works fi

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信