✨ lambda
- Create an S3 Bucket with “open” read permissions, so that anyone can see the images/files in their browser
- A user should be able to upload an image at any size, and update a dictionary of all images that have been uploaded so far
- When an image is uploaded to your S3 bucket, it should trigger a Lambda function which must:
- Download a file called “images.json” from the S3 Bucket if it exists
- The images.json should be an array of objects, each representing an image. Create an empty array if this file is not present
- Create a metadata object describing the image: Name, Size, Type, etc.
- Append the data for this image to the array
- Note: If the image is a duplicate name, update the object in the array, don’t just add it
- Upload the images.json file back to the S3 bucket
- This Lambda can be used to push metadata from images you upload to an S3 bucket into an array
- Create an S3 bucket
- Add an images.json file to your bucket that consists of an empty array
[]
- Add your S3 bucket to this lambda function as a trigger
- Start uploading images to your S3 bucket! Their meta data will now store in your images.json file in the bucket
- The array takes in an object with the properties of name, size, and type
- These objects are stored in an array in an images.json file
- Make sure your file is named images.json
- This current lambda does not cover edge cases for repeate files
// Example of returned data
{
"name": "cat.jpg",
"size": 66609,
"type": "image/jpeg"
},
// incoming event payload
{
"AcceptRanges": "bytes",
"LastModified": "2021-05-12T02:54:26.000Z",
"ContentLength": 1575343,
"ETag": "e18692a8d5b3f413b7c50e8e71a92f1e",
"ContentType": "image/jpeg",
"Metadata": {},
"Body": {
"type": "Buffer",
"data": []
}
}