Hi,
I'm trying to develop direct fileuploads to S3 for my app. I'm
following the github tutorial for this and everything is more or less
ok but get an error message when trying to make the post processing.
I did the following:
I have an activerecord model called clip.rb:
class Clip < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
mount_uploader :avatar, AvatarUploader
attr_accessible :id, :avatar, :name, :clipat_file_name, :attachable_id, :attachable_type, :clipat, :project_id, :user_id, :path, :parent_id,
def save_and_process_avatar(options = {})
if options[:now] or 1==1
self.remote_avatar_url = avatar.direct_fog_url(:with_path =>
true)
# self.clipat_file_size = avatar.file_size
# self.clipat_content_type = avatar.content_type
save
else
Resque.enqueue(AvatarProcessor, attributes)
end
end
Then I have an uploader: avatar_uploader.rb
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
include CarrierWaveDirect::Uploader
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}" #I
removed /#{
model.id} from the template because it creates an empty
directory on the server. But If I put it back, the same problem
remains
end
version :thumb do
process :resize_to_limit => [50, 50]
end
end
and an avatar controller:
class AvatarsController < ApplicationController
def new
@uploader = Clip.new.avatar
@uploader.success_action_redirect = '
http://localhost:3000/clips'
end
end
and finally my clip_controller:
class ClipsController < ApplicationController
def index
if params[:key]
key=params[:key].split("/")
clip = Clip.new
clip.attachable_id = key[3]
clip.attachable_type = "Pmdocument"
clip.key = params[:key]
# clip.save
clip.save_and_process_avatar
end
@clips = Clip.where("avatar is not null")
respond_to do |format|
format.html # index.html.erb
format.json { render json: @clips.collect { |p|
p.to_jq_upload }.to_json }
end
end
When I upload a file, if I just save my "clip", everything is ok. If I
use the save_and_process method however, an error arises at line:
self.remote_avatar_url = avatar.direct_fog_url(:with_path =>
true)
This is the error message:
OpenURI::HTTPError (403 Forbidden):
app/models/clip.rb:38:in `save_and_process_avatar'
app/controllers/clips_controller.rb:22:in `index'
Rendered /Users/nico/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/
lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
Rendered /Users/nico/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/
lib/action_dispatch/middleware/templates/rescues/
_request_and_response.erb (1.2ms)
Rendered /Users/nico/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/
lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
within rescues/layout (5.2ms)
I've been hanging on this for two days so, any help would be greatly
appreciated!!! Thanks!!! Nicolas.