我正在尝试找出最好的方法是什么。
我有一个启用了 activeStorage 的 Rails API,将 pdf 文件发送到 S3 存储桶。我有另一个 Rails API,它是一个电子邮件微服务。
我想从我的主要 Rails API 向我的电子邮件微服务发送请求,请求中包含文件附件,然后将其附加到我的电子邮件中。
我在下面遇到的解决方案似乎可以完成此操作,但前提是邮件程序发生在同一 API 上:-
class Product < ApplicationRecord
has_one_attached :photo
end
class PhotoMailer < Applicationmailer
default from: "default@example.com"
def new_photo_email
photo = params[:product].photo
attachments[photo.filename.to_s] = photo.download
mail(to: "one@example.com",subject: "Nueva photo")
end
end
class PhotoMailerPreview < actionmailer::Preview
def new_photo_email
PhotoMailer.with(product: Product.first).new_photo_email
end
end
即它使用了 activeStorage 的 download
方法。
当我将文件发送到另一个 API 时,这不起作用。实现这一目标的最佳方法是什么?我可以只发送文件 URL,然后在我的电子邮件服务中使用 File.read(url)
吗?或者有没有办法通过我的电子邮件服务可以抓取的 HTTP 请求发送文件?