Add image upload functionality and enhance inventory template with image rendering
This commit is contained in:
parent
ca3417c269
commit
a2b035f522
8 changed files with 84 additions and 15 deletions
|
|
@ -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"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue