Add image upload functionality and enhance inventory template with image rendering

This commit is contained in:
Yaro Kasear 2025-07-11 11:48:53 -05:00
parent ca3417c269
commit a2b035f522
8 changed files with 84 additions and 15 deletions

View file

@ -10,17 +10,22 @@ from ..models import Photo
photo_bp = Blueprint("photo_api", __name__)
def save_photo(file, model: str) -> str:
# Generate unique path
rel_path = generate_hashed_filename(file, model)
# Absolute path to save
assert current_app.static_folder
abs_path = os.path.join(current_app.static_folder, rel_path)
os.makedirs(os.path.dirname(abs_path), exist_ok=True)
rel_path = generate_hashed_filename(file, model)
abs_path = os.path.join(current_app.static_folder, "uploads", "photos", rel_path)
dir_path = os.path.dirname(abs_path)
if not os.path.exists(dir_path):
os.makedirs(dir_path, exist_ok=True)
print("Saving file:")
print(" - Model:", model)
print(" - Relative path:", rel_path)
print(" - Absolute path:", abs_path)
print(" - Directory exists?", os.path.exists(dir_path))
file.save(abs_path)
return rel_path
@photo_bp.route("/api/photos", methods=["POST"])