我有一个简短的问题.是否可以保存文件而不通过表单实际上传?
例如,假设我正在查看电子邮件中的附件,我想使用回形针保存它们.我该怎么做呢?我是否需要在某处手动调用save_file(或类似的东西)?
任何帮助将非常感激!
我正在尝试使用回形针为带有图片的模型编写测试.我正在使用测试框架默认,没有shoulda或rspec.在这种情况下,我该如何测试呢?我应该真的上传文件吗?我该如何在夹具中添加文件?
我正在使用Paperclip并为我的一个附件设置了一个default_url选项:
:default_url => '/images/missing_:style.png'
Run Code Online (Sandbox Code Playgroud)
自从目录移动后,资产管道显然不喜欢这样.处理这个问题的最佳方法是什么?我对这张照片有两种风格(迷你和拇指).
任何Paperclip向导都知道你是否可以在使用Paperclip保存图像时,还可以将图像尺寸(宽度和高度)保存在2个额外的字段中?如何在Paperclip上传过程中获得此类数据?
我随着时间的推移,改变了大小的交易大小.通过这些更改,用户上传到网站,因此很少有人拥有不同大小的拇指.我想重新压缩或刷新这些,所以我进入我的根并输入:
rake paperclip:refresh class=Deal
Run Code Online (Sandbox Code Playgroud)
没有为拇指大小做任何事情..然后我在脚本/控制台:
Deal.find(987).reprocess!
回复此:
NoMethodError: undefined method `reprocess!' for #<Deal:0xb68a0988>
from /data/HQ_Channel/releases/20100607130346/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:260:in `method_missing'
from (irb):7
Run Code Online (Sandbox Code Playgroud)
我的交易课是这样的:
=> Deal(id: integer, organization_id: integer, deal: string, value: string, what: string, description: string, image_file_name: string, image_content_type: string, image_file_size: integer, image_updated_at: datetime, created_at: datetime, updated_at: datetime, deal_image_file_name: string, deal_image_content_type: string, deal_image_file_size: integer, deal_image_uploaded_at: datetime)
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能让它重新处理原件,使拇指在当前拇指大小参数中的大小正确?
更新:我发现附件包含在Paperclip中.有趣的是方法喜欢.save和.updated_at工作.但是reprocess!其他一些方法却没有.有什么味道明显不合适吗?
当我尝试使用Paperclip gem上传图像时出现此错误:
NoMethodError(<ActionDispatch :: Http :: UploadedFile:0x000000025387f0>的未定义方法`stringify_keys')
class MenuItem < ActiveRecord::Base
has_one :image
end
class Image < ActiveRecord::Base
belongs_to :menu_item
has_attached_file :image, :styles => {
:large => "640x480",
:medium => "300x300",
:thumb => "100x100"
}
end
Run Code Online (Sandbox Code Playgroud) 我一直在使用paperclip和aws-s3:
def authenticated_url(style = nil, expires_in = 90.minutes)
AWS::S3::S3Object.url_for(attachment.path(style || attachment.default_style), attachment.bucket_name, :expires_in => expires_in, :use_ssl => true)
end
Run Code Online (Sandbox Code Playgroud)
新的回形针使用AWS-SDK gem,它会打破这个错误:
undefined method `url_for' for AWS::S3:Class
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何使用此方法来使用新的AWS-SDK gem?
所以,我想将图像调整为FIXED宽度,但比例高度.
我一直在尝试各种各样的运营商:
380x242#380x242> 380!x242 380x242 <
它们都没有达到预期的效果.有帮助吗?我希望它填充或调整宽度为380,然后调整高度/缩小高度所用的相同因子,将图像缩小或调整为380宽.
该场景是一个普通模型,其中包含回形针附件以及具有各种验证的其他一些列.当由于与附件无关的验证错误而无法保存要创建对象的表单时,会保留字符串等列并为用户保留预填充,但选择用于上载的文件完全丢失且必须由用户重新选择.
在模型验证错误的情况下,是否有标准方法来保留附件?这似乎是一个非常常见的用例.
在没有所有者的情况下保存文件然后在成功保存之后重新连接到对象的解决方案似乎是不优雅的,所以我希望避免这种情况.
我正在使用Paperclip/S3进行文件上传.我上传文本类文件(不是.txt,但它们本质上是.txt).在show controller中,我希望能够获取上载文件的内容,但不要将内容视为其属性之一.我能在这做什么?
attachment_file_name: "test.md", attachment_content_type: "application/octet-stream", attachment_file_size: 58, attachment_updated_at: "2011-06-22 01:01:40"
Run Code Online (Sandbox Code Playgroud)
PS - 似乎所有的Paperclip教程都是关于图像,而不是文本文件.
paperclip ×10
amazon-s3 ×1
attachment ×1
file-upload ×1
imagemagick ×1
rake ×1
ruby ×1
unit-testing ×1
validation ×1