【问题标题】:Sitemap_generator fails to uploadSitemap_generator 上传失败
【发布时间】:2023-04-07 05:15:01
【问题描述】:

我已按照 couple of pages 上的说明获取站点地图以生成并上传到我的 S3 存储桶。站点地图正在生成,但未上传。

我正在使用carrierwave进行上传,对于图片上传来说效果很好。

密钥文件似乎是 config/sitemap.rb。这是我的:

require 'rubygems'
require 'sitemap_generator'

# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "https://www.driverhunt.com"

# pick a place safe to write the files
SitemapGenerator::Sitemap.public_path = 'tmp/'

# store on S3 using #Fog# Carrierwave
SitemapGenerator::Sitemap.adapter = SitemapGenerator::WaveAdapter.new
# SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new
# This is a different problem to the one in the question, but using this second adaptor gives the error: "...lib/fog/storage.rb:27:in `new':  is not a recognized storage provider (ArgumentError)"

# inform the map cross-linking where to find the other maps
SitemapGenerator::Sitemap.sitemaps_host = "http://#{ENV['S3_BUCKET']}.s3.amazonaws.com/"

# pick a namespace within your bucket to organize your maps
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'

SitemapGenerator::Sitemap.create do
  add '/home', :changefreq => 'daily', :priority => 0.9
  # add '/contact_us', :changefreq => 'weekly'
end
# SitemapGenerator::Sitemap.ping_search_engines # Not needed if you use the rake tasks

发生了什么事?如何调试载波上传?

【问题讨论】:

    标签: ruby-on-rails heroku amazon-s3 carrierwave sitemap-generator-gem


    【解决方案1】:

    我会回答这个问题,因为您对 S3Adapter 的评论让我想到了这个话题,而我正在谷歌搜索不认可的提供者。如果您使用 S3Adapter 重新打开评论并执行以下操作,您将使其正常工作。

    如果您没有为 fog-aws gem 指定任何 fog ENV VARS,您将收到错误消息:

    ArgumentError:  is not a recognized provider
    

    通过将 SitemapGenerator::S3Adapter.new

    用作适配器

    上面的设置非常好,只需使用 S3Adapter.new 而不是 WaveAdapter! 您得到的错误(我也得到了)是由于 SitemapGenerator::S3Adapter 使用 fog-aws 并使其默认运行你应该有以下 ENV VARS:

    ENV['AWS_ACCESS_KEY_ID']     = XXX
    ENV['AWS_SECRET_ACCESS_KEY'] = XXX
    ENV['FOG_PROVIDER']          = AWS
    ENV['FOG_DIRECTORY']         = your-bucket-name
    ENV['FOG_REGION']            = your-bucket-region (ex: us-west-2)
    

    如果您缺少以下任何一项,您将收到错误消息:

    ArgumentError:  is not a recognized provider
    

    或者,如果您出于某种原因想要避免使用 ENV VARS,则应在初始化适配器时指定值,如下所示:

    SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(fog_provider: 'AWS',
                                         aws_access_key_id: 'your-access-key-id',
                                         aws_secret_access_key: 'your-access-key',
                                         fog_directory: 'your-bucket',
                                         fog_region: 'your-aws-region')
    

    但是,仅使用上述 ENV VARS 就可以了,并且可以启动并运行您的站点地图。此设置已使用 sitemap_generator 版本进行测试:5.1.0


    对于您的问题: 图像上传工作,因为它不需要与 WaveAdapter 完全相同的配置。我猜您的carrierwave.rb 文件缺少以下内容:

     config.cache_dir = "#{Rails.root}/tmp/"
     config.permissions = 0666
    

    载波初始化器的完整配置可以在这里找到: Generate Sitemaps on read only filesystems like Heroku检查您是否缺少某些东西或使用其他适配器

    但是,我认为您的问题与生产环境中缺少 ENV VARS 有关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-20
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-25
      • 2016-10-04
      相关资源
      最近更新 更多