回形针,S3,Heroku:缺少图像 [英] Paperclip, S3, Heroku: Missing Image

查看:116
本文介绍了回形针,S3,Heroku:缺少图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长时间的观众,第一次提问。我搜索了这个主题,但不相信我找到了答案。



我有一个Post模型,它有一个图像。我使用Paperclip gem,保存到Amazon S3,并在Heroku上托管。



文件上传表单工作正常,因为我可以看到图像发送给我S3桶。



问题在于,图片实际上并未显示在制作中。



这是我的模型:

  class Post< ActiveRecord :: Base 
attr_accessor:image_file_name,:image_content_type,:image_file_size,:image_updated_at
belongs_to:用户
has_many:评论

has_attached_file:图片,样式:{中等:700x500#,小:350x250> }
validates_attachment_content_type:image,content_type:/\Aimage\/.*\/



 #Paperclip / AWS需要
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV ['S3_BUCKET_NAME'],
:access_key_id => ENV ['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV ['AWS_SECRET_ACCESS_KEY']
}
}

这里是我的节目。 html.haml文件:

  .clearfix 
.post_image_description
= image_tag @ post.image.url( :中)
.description = simple_format(@ post.address)
.description = simple_format(@ post.description)

不应该 @ post.image.url 足够吗?我可能错过了什么可以正确路由到图像?



这是我看到当我拉 Heroku Logs

  2015-06-23T15:38:26.181383 + 00:00 app [web.1]:ActionController :: RoutingError(没有路线匹配[GET]/images/medium/missing.png):

这里是我的项目存储库: https://github.com/lucasvocos/pitstop



请让我知道是否还有其他问题需要提供。因为这是我第一次问。谢谢大家。

解决方案

我有一个类似的问题,上传工作正常,但显示屏显示链接已断开。我检查了链接的源代码,它没有指向S3上显示的图像的URL。我不得不将主机名添加到我的回形针配置中。

  config.paperclip_defaults = {
:storage => :s3,
:s3_host_name => 's3-us-west-2.amazonaws.com',
:s3_credentials => {
:bucket => ENV ['S3_BUCKET_NAME'],
:access_key_id => ENV ['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV ['AWS_SECRET_ACCESS_KEY']
}
}


Long time viewer, first time asker. I've searched for this topic but don't believe I've found the answer.

I have a Post model that has an image. I'm using the Paperclip gem, saving to Amazon S3, and hosting on Heroku.

The file upload form works fine, because I can see that images are sent to my S3 bucket.

The issue is that, the images don't actually show in production.

Here's my model:

class Post < ActiveRecord::Base
    attr_accessor :image_file_name, :image_content_type, :image_file_size, :image_updated_at
    belongs_to :user
    has_many :reviews

    has_attached_file :image, styles: { medium: "700x500#", small: "350x250>" }
    validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/

And here's my config/production.rb:

# Required for Paperclip / AWS
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
    :bucket => ENV['S3_BUCKET_NAME'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    }
}

And here's my show.html.haml file:

.clearfix
    .post_image_description
        = image_tag @post.image.url(:medium)
        .description= simple_format(@post.address)
        .description= simple_format(@post.description)

Shouldn't the @post.image.url be enough? What may I be missing to properly route to the image?

This is what I see when I pull Heroku Logs:

2015-06-23T15:38:26.181383+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/images/medium/missing.png"):

For reference, here's my repository for the project: https://github.com/lucasvocos/pitstop

Please let me know if there is anything else to provide in the question, too. As this is my first time asking. Thanks everyone.

解决方案

I had a similar problem that the upload was working but the display was showing a broken link. I checked the source for the link and it was not pointing to the url shown for the image on S3. I had to add the host name to my paperclip config

  config.paperclip_defaults = {
  :storage => :s3,
  :s3_host_name => 's3-us-west-2.amazonaws.com',
  :s3_credentials => {
    :bucket => ENV['S3_BUCKET_NAME'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
  }

这篇关于回形针,S3,Heroku:缺少图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆