Created
March 12, 2019 23:28
-
-
Save DavidWells/442df449cdc879b21c1378b59eed23b6 to your computer and use it in GitHub Desktop.
Handle Zip uploads through lambda function
This file contains 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
/** | |
* For future use | |
* Handle Zip uploads through lambda | |
*/ | |
const AWS = require('aws-sdk') | |
const s3 = new AWS.S3() | |
const fileType = require('file-type') | |
const sha1 = require('sha1') | |
exports.handler = function(event, context) { | |
let request = event.body | |
let base64String = request.base64String | |
let buffer = new Buffer(base64String, 'base64') | |
let fileMime = fileType(buffer) | |
if (fileMime === null) { | |
return context.fail('The string suppplied is not a file type') | |
} | |
let file = getFile(fileMime, buffer) | |
let params = file.params | |
s3.putObject(params, function(err, data) { | |
if (err) { | |
return console.log(err) | |
} | |
return console.log('File URL', file.full_path) | |
}) | |
} | |
/* | |
exports.handler = (event, context, callback) => { | |
let encodedImage = JSON.parse(event.body).user_avatar | |
let decodedImage = Buffer.from(encodedImage, 'base64') | |
var filePath = 'avatars/' + event.queryStringParameters.username + '.jpg' | |
var params = { | |
'Body': decodedImage, | |
'Bucket': 'find-my-mate-hasangi', | |
'Key': filePath | |
} | |
s3.upload(params, function(err, data) { | |
if (err) { | |
callback(err, null) | |
} else { | |
let response = { | |
'statusCode': 200, | |
'headers': { | |
'my_header': 'my_value' | |
}, | |
'body': JSON.stringify(data), | |
'isBase64Encoded': false | |
} | |
callback(null, response) | |
} | |
}) | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment