我试图在S3上根据信息设置一个简单的静态Angular网站:http: //docs.aws.amazon.com/gettingstarted/latest/swh/website-hosting-intro.html
我想通过需要发送sendgrid api密钥的表单发送电子邮件.显然,我想使用环境变量来避免在代码中使用密钥.如何在S3中设置环境变量?
我查看了aws-cli工具,但它只显示了AWS特定环境变量的示例.在AWS/S3控制台中是否有可以设置这些?
BTW-我想使用这个演示sendgrid服务的Angular服务:https: //github.com/onaclovtech/sendgrid/blob/master/sendgrid.js
我是React的新手.我正在寻找一种将照片上传到Cloudinary的好方法.我看到了Cloudinary小部件,但是我在React应用程序中实现它时遇到了麻烦,如下所述:https://cloudinary.com/blog/how_to_build_an_image_library_with_react_cloudinary#uploading_images
我把script标签放在index.html体中:
<script src="//widget.cloudinary.com/global/all.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
然后尝试在组件中使用:
class Landing extends Component {
uploadWidget() {
cloudinary.openUploadWidget(
{ cloud_name: 'minetoo', upload_preset: 'mine', tags: ['xmas'] },
function(error, result) {
console.log(result);
}
);
}
...
Run Code Online (Sandbox Code Playgroud)
但我得到错误:'cloudinary'没有定义
我的应用程序的样板是使用create-react-app生成的,如果这很重要的话.
我正在使用用 python 2.7x 编写的 AWS Lambda 函数,该函数下载、保存到 /tmp ,然后将图像文件上传回存储桶。
我的图像元数据从原始存储桶开始,带有 http 标头,如 Content-Type= image/jpeg 等。
使用 PIL 保存图像后,所有标题都消失了,只剩下 Content-Type = binary/octet-stream
据我所知,由于 PIL 的工作方式, image.save 正在丢失标题。如何保留元数据或至少将其应用于新保存的图像?
我看过帖子暗示这个元数据在 exif 中,但我试图从原始文件中获取 exif 信息并应用到保存的文件中,但没有运气。反正我不清楚它在exif数据中。
部分代码给出了我在做什么的想法:
def resize_image(image_path):
with Image.open(image_path) as image:
image.save(upload_path, optimize=True)
def handler(event, context):
global upload_path
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'].encode("utf8"))
download_path = '/tmp/{}{}'.format(uuid.uuid4(), file_name)
upload_path = '/tmp/resized-{}'.format(file_name)
s3_client.download_file(bucket, key, download_path)
resize_image(download_path)
s3_client.upload_file(upload_path, '{}resized'.format(bucket), key)
Run Code Online (Sandbox Code Playgroud)
感谢 Sergey,我改为使用 get_object 但响应缺少元数据:
response = s3_client.get_object(Bucket=bucket,Key=key)
Run Code Online (Sandbox Code Playgroud)
response= {u'Body': , u'AcceptRanges': …
我有一个模型与planting_date_begin和planting_date_end.我想检索所有planting_date_begin..planting_date_end与日期重叠的日期的记录current_week
例如:如果planting_date_begin:3/5/2017和planting_date_end:2017年3月12日,本周是2017年3月26日2017年1月1日,它不包含在查询中.
如果planting_date_begin:3/1/2017和:2017年planting_date_end4月15日它将包括在内.
我设置current_week范围:
today = Date.today
days_in_week = today.at_beginning_of_week..today.at_end_of_week
Run Code Online (Sandbox Code Playgroud)
这种语法不对,但我想做的事情如下:
Planting.where((planting_date_begin..planting_date_end).overlaps?(days_in_week) )
Run Code Online (Sandbox Code Playgroud)
处理这个问题的简洁方法是什么?顺便说一下,我正在使用postgres,以防有不同的方法.