Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ <h5>
addRemoveLinks: true,
createImageThumbnails: false,
previewTemplate: previewTemplate,
<!--Support folder upload (not compatible in some browsers)-->
init: function() {
this.hiddenFileInput.setAttribute("webkitdirectory", true);
},
accept: function (file, done) {
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
Expand All @@ -71,7 +75,9 @@ <h5>
};
req.open("POST",'/get-presigned-post');
req.setRequestHeader("Content-type", "application/json; charset=UTF-8");
req.send();
req.send(JSON.stringify({
"fp": file.webkitRelativePath,
}));
},
});

Expand Down