Skip to content

Instantly share code, notes, and snippets.

@baodinh
baodinh / go
Created Aug 26, 2020
Convert data:image/png;base64,iVBORw0KGgoAAA to []byte
View go
func streamToByte(stream io.Reader) []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.Bytes()
}
// pass reader to NewDecoder
dec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(base64string[i+1:]))
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
View gist:eda94e62a34b9049244a80e55b337ef3
var AWS = require("aws-sdk");
AWS.config.update({
accessKeyId: "",
secretAccessKey: "",
region: "us-west-2"
});
var s3 = new AWS.S3();
var bucketName = "movieinfos3";
View gist:9ffa7f7fbcf7e89db36dfecc3a29c229
<p>This topic describes how to Create AWS Lambda Node.js function that gets all images from S3, and deploy it into AWS API Gateway.</p>
<p>Scenario: </p>
<p>In S3 has the object contains the images arranged by movieid(folder) like:</p>
<div class="text-center"><img src="https://s3-us-west-2.amazonaws.com/baodinh.blog/gateway/15.png"/></div>
<p>I want to create api to access all of the images by movieid. So the result api will be like this:</p>
<pre>https://z5d4qclzwd.execute-api.usest2.amazonaws.com/movie/getimages?id=207932 </pre>
<div class="text-center"><img src="https://s3-us-west-2.amazonaws.com/baodinh.blog/gateway/1.png"/></div>
<p>This documentation guides you through our simple Node.js Lambda example function in detail.</p>
<p>Note: Strongly suggests you familiarize yourself with <a href="http://docs.aws.amazon.com/lambda/latest/dg/programming-model.html">Programming Model (Node.js)</a> in the AWS Lambda Developer Guide before continuing.</p>
<p>Example content:</p>
You can’t perform that action at this time.