Skip to content

Instantly share code, notes, and snippets.

@MareArts
Created May 2, 2019 08:15
Show Gist options
  • Save MareArts/0c683ab1eebc24139f6d8751dd7a1723 to your computer and use it in GitHub Desktop.
Save MareArts/0c683ab1eebc24139f6d8751dd7a1723 to your computer and use it in GitHub Desktop.
//////////lambda side /////////////////////////////////////////
//node.js
// function to encode file data to base64 encoded string
function base64_encode(file) {
// read binary data
var bitmap = fs.readFileSync(file);
// convert binary data to base64 encoded string
return new Buffer(bitmap).toString('base64');
}
var base64str = base64_encode("file_path_name_in_lambda");
const response = {
statusCode: 200,
img_base64:img_array,
};
///////////////////////////////////////////////////////////////
/////////client side /////////////////////////////////////////
//python
r = requests.post(....)
img_base64 = r.json()['img_base64']
imgdata = base64.b64decode(img_base64)
# save image
with open(FilePath+v1, "wb") as fh:
fh.write(imgdata)
//////////////////////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment