You still need to use the S3 API to manipulate your buckets.

As Richard mentioned, Paperclip is a good tool for attaching image
attachments to Ruby/Rails model classes.

If you want to post images to S3 without and associated model, take a
look at the official amazon web services sdk for Ruby:
http://aws.amazon.com/articles/8621639827664165

-Jesse

On Mar 30, 1:30 pm, Anil Punjabi <[email protected]> wrote:
> Hello,
>
> I am trying to upload a file from a HTML form, to a Rails app to finally go
> to S3 but I keep getting this "No such file or directory" error.
>
> My S3 policy is very generic with permissions for anonymous
> uploads/downloads.
>
> Any suggestions would be greatly appreciated.
>
> Here's a snippet of the rails code that receives the web form and posts to
> S3.
> def uploadpic
>     uploaded_io = params[:pic]
>     File.open(('http://s3.amazonaws.com/heroku-rails-bucket/'+
> uploaded_io.original_filename), 'wb') do |file|
>         file.write(uploaded_io.read)
>     end
> end
>
> Here's the generic web form code: /uploadfile.html
> <html>
> <head>
>     <title></title>
> </head>
> <body>
> <form method="post" action="/uploadpic" enctype="multipart/form-data">
>     <input type="hidden" name="id" value="12345" />
>     <input type="file" name="pic" />
>     <input type="submit" />
> </form>
> </body>
> </html>
>
> I've added: require 'open-uri' at the beginning of this file and in the
> Gemfile (as per another Stackoverflow post).
>
> Is there any other gem that will make the S3 import work correctly?
>
> Here's the heroku log file:
>
> GET clearslide.heroku.com/fileupload.html dyno=web.1 queue=0 wait=0ms
> service=7423ms status=200 bytes=371
> 2012-03-30T18:03:45+00:00 app[web.1]: cache: [GET /fileupload.html] miss
> 2012-03-30T18:03:45+00:00 heroku[nginx]: 67.164.91.9 - -
> [30/Mar/2012:18:03:45 +0000] "GET /fileupload.html HTTP/1.1" 200 371 "-"
> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML,
> like Gecko) Chrome/17.0.963.83 Safari/535.11" clearslide.heroku.com
> 2012-03-30T18:03:57+00:00 app[web.1]:
> 2012-03-30T18:03:57+00:00 app[web.1]: Started POST "/uploadpic" for
> 67.164.91.9 at 2012-03-30 11:03:57 -0700
> 2012-03-30T18:03:57+00:00 app[web.1]:
> 2012-03-30T18:03:57+00:00 app[web.1]:   Parameters: {"id"=>"12345",
> "pic"=>#<ActionDispatch::Http::UploadedFile:0x00000002d00460
> @original_filename="Kabam3.png", @content_type="image/png",
> @headers="Content-Disposition: form-data; name=\"pic\";
> filename=\"Kabam3.png\"\r\nContent-Type: image/png\r\n",
> @tempfile=#<File:/app/tmp/RackMultipart20120330-1-1k697hr>>}
> 2012-03-30T18:03:57+00:00 app[web.1]: Processing by
> MessagesController#uploadpic as HTML
> 2012-03-30T18:03:57+00:00 app[web.1]: Completed 500 Internal Server Error
> in 1ms
> 2012-03-30T18:03:57+00:00 app[web.1]: *Errno::ENOENT (No such file or
> directory -http://s3.amazonaws.com/heroku-rails-bucket/Kabam3.png):*
> 2012-03-30T18:03:57+00:00 app[web.1]:
> 2012-03-30T18:03:57+00:00 app[web.1]:
> app/controllers/messages_controller.rb:89:in `uploadpic'

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.

Reply via email to