This commit is contained in:
louiscklaw
2025-01-31 22:33:28 +08:00
parent 2f92062c07
commit 5833d552e9
689 changed files with 7855 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
from flask import Flask, request, send_from_directory
from werkzeug.utils import secure_filename
import tempfile
import json
from pprint import pprint
from flask_cors import CORS
app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
app.config['UPLOAD_FOLDER'] = tempfile.gettempdir()
CORS(app)
@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
print("hello post request")
pprint(request.files)
# f = request.files['file']
# f.save(secure_filename(f.filename))
# print("helloworld")
# return json.dumps({'hello':'world'})
return json.dumps({'hello':'world'})
@app.route('/uploads/<filename>')
def download_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
if __name__ == '__main__':
app.run(debug = True)

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -ex
npx nodemon --ext py --exec "python ./main.py"

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","age":30}' http://localhost:5000/api/data
# curl http://localhost:5000/api/data
curl -F "file=@test.txt" http://localhost:5000/uploader

View File

@@ -0,0 +1 @@
helloworld