add Dockerfile + App
This commit is contained in:
parent
9158d64758
commit
cae938ca7e
3 changed files with 57 additions and 0 deletions
22
Dockerfile
Normal file
22
Dockerfile
Normal file
|
@ -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"]
|
33
app.py
Normal file
33
app.py
Normal file
|
@ -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
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
Flask==2.0.1
|
||||
Flask-Cors==3.0.10
|
Reference in a new issue