Spaces:
Sleeping
Sleeping
DmitrMakeev
commited on
Commit
•
14af27b
1
Parent(s):
067e3ba
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ from flask import Flask, request, render_template_string, send_from_directory, j
|
|
2 |
from flask import render_template
|
3 |
import sqlite3
|
4 |
import os
|
5 |
-
|
6 |
own_url = os.getenv('own_url') # URL сервера
|
7 |
|
8 |
|
@@ -21,7 +21,7 @@ app = Flask(__name__, template_folder="./")
|
|
21 |
app.config['DEBUG'] = True
|
22 |
|
23 |
UPLOAD_FOLDER = 'static'
|
24 |
-
|
25 |
|
26 |
# Создание директории, если она не существует
|
27 |
if not os.path.exists(UPLOAD_FOLDER):
|
@@ -108,9 +108,14 @@ def upload_file():
|
|
108 |
file = request.files['photo']
|
109 |
if file.filename == '':
|
110 |
return "No selected file", 400
|
111 |
-
|
|
|
|
|
|
|
112 |
file.save(save_path)
|
113 |
-
|
|
|
|
|
114 |
|
115 |
@app.route('/image', methods=['GET'])
|
116 |
def get_image():
|
|
|
2 |
from flask import render_template
|
3 |
import sqlite3
|
4 |
import os
|
5 |
+
import uuid
|
6 |
own_url = os.getenv('own_url') # URL сервера
|
7 |
|
8 |
|
|
|
21 |
app.config['DEBUG'] = True
|
22 |
|
23 |
UPLOAD_FOLDER = 'static'
|
24 |
+
|
25 |
|
26 |
# Создание директории, если она не существует
|
27 |
if not os.path.exists(UPLOAD_FOLDER):
|
|
|
108 |
file = request.files['photo']
|
109 |
if file.filename == '':
|
110 |
return "No selected file", 400
|
111 |
+
|
112 |
+
# Генерация уникального имени файла
|
113 |
+
unique_filename = str(uuid.uuid4()) + os.path.splitext(file.filename)[1]
|
114 |
+
save_path = os.path.join(UPLOAD_FOLDER, unique_filename)
|
115 |
file.save(save_path)
|
116 |
+
|
117 |
+
# Вывод концовки имени файла
|
118 |
+
return f"File uploaded successfully. New filename: {unique_filename}", 200
|
119 |
|
120 |
@app.route('/image', methods=['GET'])
|
121 |
def get_image():
|