本文介绍了在控制器 (ApplicationMailer) 中的 S3 上打开远程图像 - 没有这样的文件或目录@rb_sysopen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开通过 Paperclip 上传到 S3 的个人资料图片,以便将其作为电子邮件的在线附件提交.

I am trying to open a profile picture uploaded to S3 through Paperclip, in order to submit it as an online attachment to an email.

虽然我得到错误:

No such file or directory @ rb_sysopen

这是我有问题的代码:

attachments.inline['profilepic'] = File.read(profilepic)

profilepic 是 S3 图像的绝对 URL(以//mybucket.S3-eu-west..... 开头)(粘贴到导航栏时,它只显示图像完美)

profilepic being an absolute URL (starting with //mybucket.S3-eu-west..... ) to the image at S3 (when pasted onto the navbar, it just shows the image perfectly)

我使用 open-uri 尝试了以下操作,但错误相同

I have tried the following using open-uri, but same error

require 'open-uri'
attachments.inline['profilepic'] = open(profilepic)

推荐答案

和你一样,你首先需要:

Like you did, you need to first:

require 'open-uri'

然后做:

uri = URI("http:"+profilepic.to_s)
attachments["profilepic"] = open(uri).read

这篇关于在控制器 (ApplicationMailer) 中的 S3 上打开远程图像 - 没有这样的文件或目录@rb_sysopen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:23