写适配器在sitemap_generator微软Azure

问题描述 投票:0回答:1

我使用sitemap_generator产生在我的回报率project.Everything Sitemaps是工作的罚款,直到now.I我主持我在Heroku上,不允许写入本地filesystem.I仍然需要一些写访问的项目,因为该站点地图文件需要上传之前完整地写出来。但是,我必须使用微软的Azure存储在sitemap_generator上市我sitemap.The适配器不包括azure.Could有人点我在正确的方向写一个适配器蔚蓝。

在qazxsw POI文章参见“配置carrierwave”我已经在我的代码进行一些更改。

但我不知道只有编辑initialiazer文件是要help.In上面的文章Carrierwave指向它采用CarrierWave的WaveAdapter this ::上传:: Base上传至CarrierWave支持的任何服务

config/initializers/azure.rb

here

请帮忙!

ruby-on-rails azure sitemap-generator-gem
1个回答
0
投票

我复制我的设置从Azure.configure do |config| config.cache_dir = "#{Rails.root}/tmp/" config.storage = :microsoft_azure config.permissions = 0666 config.microsoft_azure_credentials = { :provider => 'azure', :storage_account_name => 'your account name', :storage_access_key => 'your key', } config.azure_directory = 'container name' end the S3 adapter

蔚蓝色的斑点宝石添加到您的Gemfile:Azure's ruby example

创建配置/初始化/ sitemap_generator / azure_adapter.rb:

gem 'azure-storage-blob'
  • 请确保您在Azure中创建的容器是一个“斑点”容器,该容器是不公开的,但斑点内的。

然后在配置/ sitemaps.rb:

require 'azure/storage/blob'

module SitemapGenerator
  # Class for uploading sitemaps to Azure blobs using azure-storage-blob gem.
  class AzureAdapter
    #
    # @option :storage_account_name [String] Your Azure access key id
    # @option :storage_access_key [String] Your Azure secret access key
    # @option :container [String]
    def initialize
      @storage_account_name = 'your account name'
      @storage_access_key = 'your key'
      @container = 'your container name (created already in Azure)'
    end

    # Call with a SitemapLocation and string data
    def write(location, raw_data)
      SitemapGenerator::FileAdapter.new.write(location, raw_data)

      credentials = {
        storage_account_name: @storage_account_name,
        storage_access_key: @storage_access_key
      }

      client = Azure::Storage::Blob::BlobService.create(credentials)
      container = @container
      content = ::File.open(location.path, 'rb') { |file| file.read }
      client.create_block_blob(container, location.filename, content)
    end
  end
end

应该这样做!

© www.soinside.com 2019 - 2024. All rights reserved.