amazon-s3 - 回形针图像未显示在 Action Mailer 电子邮件中
问题描述
我正在编写一个非常简单的电子邮件模板,它发送带有嵌入图像的 HTML 电子邮件。图像使用 Paperclip gem 存储在 AWS S3 中:
<%= image_tag @press_release.image.try(:attachment).try(:url, :preview), alt: 'zimplePR', style: 'width: 85%; max-height: 200px; object-fit: cover;' %>
在生产中,该image_tag
助手在我的 web 视图中充当了一个魅力,但由于某种原因,它没有显示在我发送的电子邮件中。
我在某处读到可能是因为 Paperclip 的完整附件 url 类似于//s3.amazonaws.com/...
并且在前面加上“http:”应该可以,但这仅适用于 Gmail,但不适用于 Apple 电子邮件。
有没有办法使用 Paperclip 将图像嵌入到 ActionMailer 模板中并显示在所有电子邮件客户端中?
解决方案
我发现了问题,这个错误的原因是因为我没有指定附件的 :http 协议:
Class Image < ApplicationRecord
has_attached_file :attachment,
:styles => {
:thumb => ['80x80>', :png],
:preview => ['600x600>', :png]
},
:convert_options =>{
:thumb => "-quality 80 -interlace Plane",
:preview => "-quality 80 -interlace Plane",
},
:default_url => 'images/missing_:style.png',
:s3_protocol => :https,
:s3_credentials => {
:bucket => Rails.application.credentials[:aws][:s3_bucket_production]
}
end
推荐阅读
- android-studio - 我可以使用带有 MobileNet 或 Deeplab 图像分割模型的 Camerax 从相机进行实时图像分割吗?
- c# - 我想为 ASP.NET Core 身份的用户创建一个帐户,但我无法将数据插入到表 dbo.AspNetUsers
- c++ - 在 C++ 中拆分没有空格的字符串
- django - 无法序列化多个对象以保存在 django rest 框架中的数据库中
- flutter - 错误:没有为类“Utf8”定义吸气剂“addressOf”
- python - 用 python 绘制一个包含 X、Y、半径、强度的矩阵
- python - 如何尽可能高效地将元组列表转换为 pandas DataFrame?
- spring-boot - com.mongodb.MongoSocketOpenException:异常打开套接字。将fladdoodle从2.03更新到3.0.0版本后
- django-views - 如何在 django 中进行批量删除?
- database - 有没有办法在 Typerom 实体中的不同连接之间创建关系?