full-stack-fastapi-template
full-stack-fastapi-template copied to clipboard
what data storage type should i use for image in SQLalchemy model?
from typing import TYPE_CHECKING
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from app.db.base_class import Base
if TYPE_CHECKING:
from .user import User # noqa: F401
class HouseItem(Base):
id = Column(Integer, primary_key=True, index=True)
title = Column(String, index=True)
description = Column(String, index=True)
#image = ??? #add here
specification = Column(String, index=True)
owner_id = Column(Integer, ForeignKey("user.id"))
owner = relationship("User", back_populates="houseitems")
or should i import another library?
LargeBinary probably if you are saving image content
I think databases are not designed to function as file storage, maybe a better way is to save the image file to some location (like a local folder on your disk, AWS-S3 or Dropbox) the database would save a string with the location of the image file
for that purpose you can use: SQLAlchemy-ImageAttach is a SQLAlchemy extension for attaching images to entity objects
I think databases are not designed to function as file storage, maybe a better way is to save the image file to some location (like a local folder on your disk, AWS-S3 or Dropbox) the database would save a string with the location of the image file
for that purpose you can use: SQLAlchemy-ImageAttach is a SQLAlchemy extension for attaching images to entity objects
storing binary representations is fine in some cases, but i would also go the bucket route if possible. no clue how a cdn would distribute bytea