Amazon s3 - paperclip - Rails3 - basic setup Noob simple problems

Hi all, I've got a feeling from other posts that this should be very
simple, but believe me I've looked around many tutorials / blogs, but
still cant even get the most basic setup working with paperclip and s3.
I am however pretty new to Rails, so could be doing something dumb.

You might need to load s3 earlier than in the model you're using it in. Maybe load it in the same time frame that Paperclip does, back in the environment.rb or if that's different in Rails3, then wherever it gets done there. Maybe try loading it before Paperclip.

Walter

Thanks for the help Walter, I tried what you said, putting them in a
different order, still doesn't quite work, although some progress, got a
different error message now!:

uninitialized constant AWS::S3::NoSuchBucket

I've set up my s3.yml file now to have the 3 buckets production,
development and test.

You've not indicated any versions for anything here. Are you running Rails.latest? Because you don't seem to be indicating particular versions of your Gems, so you are by default getting the latest of those... Try finding the exact versions of the Gems that go with your particular Rails (not easy, I know) and set them definitively in your environment/gemfile.

Walter

Did you set up your S3 bucket for your app?

I wrote up how to do this set up here http://www.arailsdemo.com/posts/15

Hopefully that will get you going.

Michael Baldock wrote in post #958147:

Thanks for the help.

@Walter - I'll have a look through the comments at the git page to see
if I can find anything about specific paperclip versions working with
rails3 / s3, and the same for aws-s3, thanks for the tip!

@ArailsDemo A. - That turoial looks really good, I'll try and go back
and do the whole thing one day! I have a couple of questions regarding
the paperclip / s3 part.

1. - Your model 'Resources' has the line
t.references :attachable, :polymorphic => true
is this important for being able to attach photos?

2. I'm inputting my photos in a different way, I have the lines:
    <%= f.label :photo %>
    <%= f.file_field :photo%>
Whereas you have:
= resource_f.input :attachment, :label => 'File'

I've tried substituing your way, and the 'new' page returns the error
   undefined method `input' for...

Is this crucial in your setup?

3. I keep coming back to the line
:path => "/:style/:id"
Which in your tutorial is
:path => "/:style/:filename"

Every example seems to have a slightly different line here, what is this
referring to? Is this the structure of me s3 account? is 'style' the
paperclip reference for 'thumb / small / post' etc? Where do you get the
word ':filename' from??

Thanks again for you help, and a great tutroial.

Mike

1. The polymorphic part isn't necessary. If you just expect to have one
model that has file attachments then it's not going to help you.
However, if you have multiple models that have attachments, then you
might want to go the polymorphic way. See
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations.

2. You're markup should work. On the website, I'm using HAML as a
replacement for ERB. Also, I'm using the 'simple form' gem. So my markup
is going to look different than yours. Plus, I'm using a nested form.

3. The :path is the file path that file will be placed in your S3
account.
In your case, you specified

:styles => { :thumb => "100x100#", :small => "150x150>" }

So when you upload a file, paperclip will generate these two image
styles for you as separate files. If the original file was bigger than
both of these styles, then you'll also have a third 'original' file.

If you have

:path => "/:attachment/:id/:style.:extension"

your S3 file path will be something like '/photo/1/thumb.png'

If you used

:path => "/:style/:id"

your S3 file path would be '/thumb/1'. This won't work because it's not
specific enough. You'll just keep overwriting the same file. ':filename'
is automatically available for you to use because each upload has to
have a filename.

If you're using Firefox, I recommend the 'S3Fox' add-on that will allow
you to browse your S3 account through Firefox.

Cheers for that, that part makes more sense now.

Still getting the same error, now using the path:

:path => "/:attachment/:id/:filename.:extension"

Another thing I noticed, when I sign in to aws-s3 through the rails
console, like this:

Base.establish_connection!(:access_key_id...

I get the message

#<AWS::S3::Connection:0x1035886e0 @http=#<Net::HTTP s3.amazonaws.com:80
open=false>,

which doesn't seem good, however following this I can still access my s3
buckets. Service.buckets returns a complete list.

is the ...open=false> message normal??

Thanks

I get that same "...open=false>" in my console when connecting to S3.
Can you transfer a file through the console commands? See

http://amazon.rubyforge.org/

Also, in the s3.yml file, do you have things in quotes?

development:
  bucket: 'teneventsdevelopment'
  access_key_id: 'asdfa324234'
  secret_access_key: 'qwer2342'