diff options
| -rw-r--r-- | Dockerfile | 22 | ||||
| -rw-r--r-- | app.py | 33 | ||||
| -rw-r--r-- | requirements.txt | 2 |
3 files changed, 57 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9e07041 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM ubuntu:focal + +# deaktiviert Nachfragen beim installieren von Paketen +ENV DEBIAN_FRONTEND=noninteractive + +# hadolint ignore=DL3008,DL3028,DL4006 +RUN apt-get update && \ + apt-get -y --no-install-recommends install \ + python3-pip && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/* + +WORKDIR /app + +COPY requirements.txt . +COPY app.py . + +RUN pip install --no-cache-dir -r requirements.txt + +EXPOSE 5000 + +CMD [ "python3", "-m" , "flask", "run"] @@ -0,0 +1,33 @@ +from flask import Flask, request, jsonify +import os + +app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = 'uploads/' +app.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024 # 5MB limit + +@app.route('/upload', methods=['POST']) +def upload_file(): + file = request.files['file'] + if file: + filename = file.filename + if not os.path.exists(app.config['UPLOAD_FOLDER']): + os.makedirs(app.config['UPLOAD_FOLDER']) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + return 'File uploaded successfully' + else: + return 'No file specified', 400 + +@app.route('/files', methods=['GET']) +def list_files(): + files = [] + for filename in os.listdir(app.config['UPLOAD_FOLDER']): + path = os.path.join(app.config['UPLOAD_FOLDER'], filename) + if os.path.isfile(path): + files.append(filename) + return jsonify(files) + +if __name__ == '__main__': + app.run() + +# curl -X POST -F 'file=@/path/to/file' http://localhost:5000/upload +# curl http://localhost:5000/files diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4e828aa --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.1 +Flask-Cors==3.0.10 |