Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7dbff21

Browse files
Added support for other image types than jpg
1 parent 6d86f54 commit 7dbff21

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

‎functions/save.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@ exports.handler = function(event, context, callback) {
3838
base64.replace(/^data:image\/\w+;base64,/, ""),
3939
"base64"
4040
);
41+
let imgtype = base64.split(";")[0].split("/")[1];
4142

4243
let filename =
4344
"img/" +
4445
Math.random().toString(36).substring(2, 15) +
4546
Math.random().toString(36).substring(2, 15) +
46-
".jpg";
47+
"." +
48+
imgtype;
4749
var params = {
4850
Body: base64data,
4951
Bucket: process.env.S3_BUCKET,
5052
Key: filename,
5153
ContentEncoding: "base64",
52-
ContentType: "image/jpeg",
54+
ContentType: `image/${imgtype}`,
5355
ACL: "public-read",
5456
};
5557
}

‎public/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ <h2>Result:</h2>
9191
document.querySelector("#image").src = base64data;
9292

9393
// save the image
94-
//var data = base64data.replace(/^data:image\/\w+;base64,/, "");
95-
var data = base64data;
94+
let data = base64data;
9695
let type = "image";
9796
save(data, type);
9897
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /