在 Ruby on Rails 中发送带有通过表单上传的附件的邮件的最佳方式
通过表单上传附件并发送电子邮件的最佳方式是什么?附件不需要存储在服务器上。
我发现了一个性感的 jQuery 上传器: https://github.com/blueimp/jQuery-File- Upload/ 和 RoR3 指南 https://github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-for-Rails-3
但是如何实现而不在服务器上保存为文件?
或者还有其他简单的方法吗?
谢谢安迪
what's the best way to upload an attachment by form and send an email? The attachment doesn't need to be stored on the server.
I found a sexy jQuery uploader: https://github.com/blueimp/jQuery-File-Upload/ and a guide for RoR3 https://github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-for-Rails-3
but how to implement without saving as file on the server?
Or is there an other easy way?
Thanks andi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的代码使用回形针,默认情况下,当您保存关联模型时,它会将文件保存到您的公共目录中。您可以在调用 save 之前使用queued_for_write 方法访问文件(并避免调用 save)。
或者:
由于文件上传和电子邮件发送都可能很慢,因此您可能需要将两者分开,以便您的应用程序对用户来说感觉更快。
1) 使用回形针保存文件。然后结束该请求并让用户知道它已排队。
2) 让后台进程或延迟作业检查您的模型,找到文件,通过电子邮件发送,然后将其删除(并根据需要更新/删除模型)。
The above code uses paperclip, which by default saves the file into your public directory when you save the associated model. You might be able to use the queued_for_write method to access the file before calling save (and avoid calling save).
Alternatively:
Since file uploads and email sends can both be slow, you might want to separate out the two so that your app feels more speedy for your users.
1) Use paperclip to save the file. Then end this request and let the user know it's queued up.
2) Have a background process or delayed job go through your model, find the file, email it, then delete it (and update/delete the model as necessary).