Skip to content

Commit

Permalink
fix S3 post not passing all fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bentsku committed Apr 11, 2024
1 parent 76b9864 commit 91660e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if [ "$os" == "Darwin" ]; then
(
cd lambdas/resize
rm -rf libs lambda.zip
docker run --platform linux/x86_64 -v "$PWD":/var/task "public.ecr.aws/sam/build-python3.9" /bin/sh -c "pip install -r requirements.txt -t libs; exit"
docker run --platform linux/x86_64 --rm -v "$PWD":/var/task "public.ecr.aws/sam/build-python3.9" /bin/sh -c "pip install -r requirements.txt -t libs; exit"
cd libs && zip -r ../lambda.zip . && cd ..
zip lambda.zip handler.py
rm -rf libs
Expand Down
5 changes: 4 additions & 1 deletion lambdas/presign/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def handler(event, context):
raise ValueError("no key given")

# make sure the bucket exists
s3.create_bucket(Bucket=bucket)
try:
s3.head_bucket(Bucket=bucket)
except Exception:
s3.create_bucket(Bucket=bucket)

# make sure the object does not exist
try:
Expand Down
18 changes: 10 additions & 8 deletions website/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,23 @@
let urlToCall = functionUrlPresign + "/" + fileName
console.log(urlToCall);

let form = this;

$.ajax({
url: urlToCall,
success: function (data) {
console.log("got pre-signed POST URL", data);

// set form fields to make it easier to serialize
let fields = data['fields'];
$(form).attr("action", data['url']);
for (let key in fields) {
$("#" + key).val(fields[key]);
}

let formData = new FormData($("#uploadForm")[0]);
let formData = new FormData()

Object.entries(fields).forEach(([field, value]) => {
formData.append(field, value);
});

// the file <input> element, "file" needs to be the last element of the form
const fileElement = document.querySelector("#customFile");
formData.append("file", fileElement.files[0]);

console.log("sending form data", formData);

$.ajax({
Expand Down

0 comments on commit 91660e1

Please sign in to comment.