Created
January 6, 2020 22:17
-
-
Save ykessler/01fc02a598c8b43830db69dd16b4ba02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/svg_to_png', async function (req, res) { | |
let params = req.body | |
let image_url = 'https://s3.amazonaws.com/' + params.s3_bucket + '/' + params.s3_key | |
// STEP 1: Convert SVG to PNG: | |
var outputBuffer = svg2png.sync(params.svg_data, {}); | |
// STEP 2: Upload to S3: | |
let s3_params = { | |
Bucket:params.s3_bucket, | |
Key:params.s3_key, | |
Body:outputBuffer, | |
ContentType:'image/png', | |
ContentDisposition:'inline', | |
ACL: 'public-read' | |
} | |
try { | |
result = await s3.putObject(params).promise(); | |
res.send(image_url) | |
} catch(err) { | |
// return error response | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment