diff --git a/app.py b/app.py index a9b9b13..41187a8 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,7 @@ from flask import Flask, render_template, jsonify, request import boto3 from botocore.client import Config -import uuid +import os app = Flask(__name__) @@ -15,12 +15,11 @@ def home(): @app.route('/get-presigned-post', methods=['POST']) def get_presigned_post(): if request.method == 'POST': - prefix = 'custom-prefix' - key = str(uuid.uuid4()) + key = request.json['fp'] s3 = boto3.client('s3', config=Config(signature_version='s3v4')) post = s3.generate_presigned_post( Bucket='myBucket', - Key="{}/{}".format(prefix, key), + Key=key, ExpiresIn=3600, ) return jsonify(post) diff --git a/templates/index.html b/templates/index.html index 71a39ed..e9f2bbb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -55,6 +55,10 @@
addRemoveLinks: true, createImageThumbnails: false, previewTemplate: previewTemplate, + + init: function() { + this.hiddenFileInput.setAttribute("webkitdirectory", true); + }, accept: function (file, done) { const req = new XMLHttpRequest(); req.onreadystatechange = () => { @@ -71,7 +75,9 @@
}; req.open("POST",'/get-presigned-post'); req.setRequestHeader("Content-type", "application/json; charset=UTF-8"); - req.send(); + req.send(JSON.stringify({ + "fp": file.webkitRelativePath, + })); }, });