Errno :: ENOENT:没有这样的文件或目录

时间:2016-03-31 17:55:07

标签: ruby-on-rails ruby amazon-web-services amazon-s3 aws-sdk

如何解决错误Errno::ENOENT: No such file or directory - /app/tmp/sitemaps?我有文件:tmp / sitemaps / sitemap.xml.gz。

$ heroku run rake sitemap:upload_to_s3
Running rake sitemap:upload_to_s3 on livetochallenge.... up, run.2043
Starting sitemap upload to S3...
rake aborted!
Errno::ENOENT: No such file or directory - /app/tmp/sitemaps

这是lib / tasks / sitemap.rake:

# Code Based Upon Comment Made In Below Tutorial Unless Specified Here
namespace :sitemap do
  desc 'Upload the sitemap files to S3'
  task upload_to_s3: :environment do
    puts 'Starting sitemap upload to S3...'
    s3 = Aws::S3::Resource.new
    bucket = s3.bucket(ENV['AWS_BUCKET']) # I refer to it as AWS not S3. I couldn't figure out the latter and not sure if it makes a difference. In production.rb paperclip_defaults I set it :bucket => ENV['AWS_BUCKET']
    Dir.entries(File.join(Rails.root, 'tmp', 'sitemaps')).each do |file_name|
      next if %w(. .. .DS_Store).include? file_name
      path = "sitemaps/#{file_name}"
      file = File.join(Rails.root, 'tmp', 'sitemaps', file_name)
      object = bucket.object(path)
      object.upload_file(file)
      puts "Saved #{file_name} to S3"
    end
  end

配置/ sitemap.rb:

SitemapGenerator::Sitemap.default_host = 'http://www.livetochallenge.com/'
SitemapGenerator::Sitemap.public_path = 'tmp/sitemaps/'

SitemapGenerator::Sitemap.create do
  add challenges_path, changefreq: 'daily'
  Challenge.find_each do |f|
    add challenge_path(f), lastmod: f.updated_at
  end
end

SitemapGenerator::Sitemap.ping_search_engines

的routes.rb

get '/sitemap.xml.gz', to: redirect("https://#{ENV['AWS_BUCKET']}.s3.amazonaws.com/sitemaps/sitemap.xml.gz"), as: :sitemap

我正在使用AWS SDK v2.2.31。

enter image description here

我按照教程Creating a sitemap with Ruby on Rails and uploading it to Amazon S3

0 个答案:

没有答案