【问题标题】:Strange behavior with AWS S3 serverless image resizingAWS S3 无服务器图像大小调整的奇怪行为
【发布时间】:2018-05-07 06:14:33
【问题描述】:

我关注了这个博客 https://aws.amazon.com/blogs/compute/resize-images-on-the-fly-with-amazon-s3-aws-lambda-and-amazon-api-gateway/

还有这个回购 https://github.com/awslabs/serverless-image-resizing

能够在 AWS S3 上动态调整图像大小。桶创建成功。每当我将图像上传到存储桶时,我都可以按照博客中的说明从 url 调整它的大小,一切正常。

问题是当从代码上传图像时(Ruby on Rails 使用回形针),然后可以正常访问图像,但是在尝试调整 url 大小时(例如 /100x200/photo.png)我在浏览器作为 json 响应

{
"message": "Internal server error"
}

The response headers are: 

Request URL:<url>
Request Method:GET
Status Code:502 
Remote Address:<IP>
Referrer Policy:no-referrer-when-downgrade
Response Headers
content-length:36
content-type:application/json
date:Thu, 23 Nov 2017 09:59:24 GMT
status:502
via:1.1 <hash>.cloudfront.net (CloudFront)
x-amz-cf-id:<id>
x-amzn-requestid:<id>
x-cache:Error from cloudfront
Request Headers
:authority:<url>
:method:GET
:path:/prod?key=<path/to/photo>
:scheme:https
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
accept-encoding:gzip, deflate, br
accept-language:en-US,en;q=0.9,de;q=0.8,ar;q=0.7
cache-control:max-age=0
upgrade-insecure-requests:1
user-agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36
Query String Parameters
view source
view URL encoded
key:<path/to/photo>

非常奇怪的是,发生错误后,当我再次手动上传相同的图像时,在存储桶中的任何地方然后我使用原始调整大小的url再次尝试 strong>,不是新上传的图片 url 导致问题,它可以正常工作,我可以调整到任何大小!

所以看起来手动上传会触发与这个图像数据相关的东西?我不知道!

【问题讨论】:

    标签: ruby-on-rails amazon-web-services amazon-s3 paperclip serverless


    【解决方案1】:

    这里的错误是你把需要的大小直接放在文件名之前,你应该把它放在整个文件路径之前。

    确保您遵循以下模式:

    http://$BucketWebsiteHost/$size/$imagePath

    例子:

    http://mybucketname.s3-website.mybucketregion.amazonaws.com/60x50/photos/attachments/000/002/002/original/image.jpg

    【讨论】:

      猜你喜欢
      • 2017-07-09
      • 2014-06-09
      • 2015-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多