11import os
22import sys
33from flask import Flask , request , jsonify
4- import uuid
54import cv2
6-
75import importlib .util
8- import sys
96from pathlib import Path
107
118module_path = Path (__file__ ).resolve ().parent .parent / 'AI' / 'main.py'
2623app .config ['UPLOAD_FOLDER' ] = UPLOAD_FOLDER
2724app .config ['ALLOWED_EXTENSIONS' ] = ['jpg' , 'png' , 'jpeg' ]
2825
26+ cod_counter = 1
2927def check_filename (filename ):
3028 return '.' in filename and filename .rsplit ('.' , 1 )[1 ].lower () in app .config ['ALLOWED_EXTENSIONS' ]
3129
3230
3331@app .route ('/upload' , methods = ['POST' ])
3432def upload_file ():
33+ global cod_counter
3534 # verific daca in cerere exista un fisier.
3635 if 'file' not in request .files :
3736 return jsonify ({'error' : 'No file part' }), 400
@@ -43,14 +42,14 @@ def upload_file():
4342 return jsonify ({'error' : 'No selected file' }), 400
4443
4544 if file and check_filename (file .filename ):
46- cod_unic = uuid .uuid4 ().hex
4745 # am creat un hash unic pe care sa il apenduiesc in fata numelui fisierului, pentru
4846 # ca daca il lasam fara, fisierele nu mai aveau denumiri distincte, si folderul
4947 # ramanea mereu doar cu o poza, la fiecare incarcare a camerei din flutter.
50- filename = f"{ cod_unic } { file .filename } "
48+ filename = f"{ cod_counter } _ { file .filename } "
5149 # concatenez cu un contor pentru ca altfel, imi punea pozele
5250 # distincte ca acelasi obiect file in folder.
5351 file .save (os .path .join (app .config ['UPLOAD_FOLDER' ], filename ))
52+ cod_counter += 1
5453 return jsonify ({'message' : 'File uploaded successfully!' }), 200
5554 else :
5655 return jsonify ({'error' : 'File type not allowed' }), 400
0 commit comments