In a Rails 4 app, I am using Paperclip and the fog-google gem to store pictures in my Google Cloud Storage bucket. Everything works great for file upload. The problem is that when I retrieve a bunch of photos to display, it is incredibly slow. The requests take waaay longer than they should. I believe the problem is that fog is authenticating each and every request so it takes a long time to retrieve a bunch of files. In my development environment, things are really snappy because the pictures are stored locally. It is only in production that the requests are really slow. The url of the stored file in the Google bucket is public, so I am wondering if there is away to tell fog not to authenticate on the GET requests. Does anyone know how I can do this so that every single request for a file is not authenticated??
#config/environments/production.rb
Rails.application.configure do
config.paperclip_defaults = {
storage: :fog,
fog_credentials: {
google_storage_access_key_id: ENV.fetch('GOOGLE_STORAGE_ID'),
google_storage_secret_access_key: ENV.fetch('GOOGLE_STORAGE_SECRET'),
provider: 'Google' },
fog_directory: '<bucket name>' }
end
#app/models/item.rb
class Item < ActiveRecord::Base
has_attached_file :image
end
#migration
class AddAttachmentImageToItems < ActiveRecord::Migration
def self.up
change_table :sitems do |t|
t.attachment :image
end
end
def self.down
remove_attachment :items, :image
end
end
