javascript - 使用 CloudFront 功能时如何进行 base64 编码/解码?
问题描述
Amazon CloudFront Function 是 AWS 推出的一项新功能。
CloudFront 函数只能使用 JavaScript 编写。
https://aws.amazon.com/blogs/aws/introducing-cloudfront-functions-run-your-code-at-the-edge-with-low-latency-at-any-scale/
我们的网站生成时间戳并使用 btoa()(Base64 编码)对其进行编码。
然后,网站向 CloudFront 函数发送包含编码时间戳的 HTTP GET 请求。
var sending_time = new Date().getTime();
var enc_sending_time = btoa(sending_time);
function generate_http_request(enc_sending_time)
{
...
}
CloudFront 函数收到 HTTP 请求后,
应使用 atob() 解码时间戳。
但是,CloudFront 函数不支持 atob()。 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-javascript-runtime-features.html
我们如何在
不使用 btoa() 和 atob()的情况下将 base64 编码为整数
,然后在 CloudFront 函数端进行 base64 解码?
(仅限 JavaScript)
解决方案
CloudFront 不支持 btoa() 和 atob() 函数,
因此我们无法使用这些函数进行 Base 64 编码/解码。
因此,作为替代方案,我们可以使用以下内容:
https ://gist.github.com/oeon/0ada0457194ebf70ec2428900ba76255
奇迹般有效!
推荐阅读
- javascript - 如何确保我使用最新的 Promise()
- asp.net-mvc - 传递(局部变量)列表
并在视图 MVC 中显示列表 - c - Scanf 和动态内存分配
- django - Django FormView:form_valid() 接受 2 个位置参数,但给出了 3 个
- python - 当文件包含来自不同目录的模块时,如何运行 python 脚本?
- ruby-on-rails - 将 ruby 全局版本更改为 2.6.4 后无法运行 rails
- python - Python - 如何在不使用第三方库的情况下读取图像像素?
- javascript - 我可以通过下一次调用将值传递给委托生成器吗?
- python-3.x - 将循环结果保存到变量中?
- php - 如何解决 Laravel “有效载荷无效”?