George -
I did the exact thing a few months ago - actually for a test environment as
I deal with credit data and cant put live data on S3. Anyhow, I tried and
really liked paperclip, but ended up just going directly with the s3 gem. I
thing there were some complications with how I wanted to be able to both
save and modify files which I found easier going with S3 gem directly.
Anyhow, here are my functions...

  def self.save_file(file_path, data)
    begin
      if USE_AMAZON_S3
        require 'aws/s3'
        file_path = file_path.gsub(FILESTORE, "") # remove the path to
filestore (leaving the app as is since S3 is for test only)
        #file_path = file_path.gsub(/^\//, "")
        AWS::S3::Base.establish_connection!(
          :access_key_id => 'zzzzz',
          :secret_access_key => 'zzzzz'
        )
        AWS::S3::S3Object.store(file_path, data, AMAZON_S3_BUCKET)
        return true if AWS::S3::Service.response.success?
      else
        FileUtils.mkdir_p
GlobalFunctions.get_path_without_file_name(file_path)
        chars_written = File.open(file_path, 'w') {|f| f.write(data) }
        return true if chars_written == data.length
      end
    rescue
      SystemError.new(:user_id => nil,
                      :account_id => nil,
                      :location => "GlobalFunctions.save_file",
                      :error => "failed to save file",
                      :incidentals => {"file_path" => file_path,
                                       "data" => data}
                      ).save
    end
    false
  end



  def self.load_file_data(path)
    begin
      if USE_AMAZON_S3
        require 'aws/s3'
        path = path.gsub(FILESTORE, "")  # remove the path to filestore
(leaving the app as is since S3 is for test only)
        AWS::S3::Base.establish_connection!(
          :access_key_id => 'zzzzz',
          :secret_access_key => 'zzzzz'
        )
        return AWS::S3::S3Object.value path, AMAZON_S3_BUCKET
      else
        return File.open(path, "r").read
      end
    rescue
      SystemError.new(:user_id => nil,
                      :account_id => nil,
                      :location => "GlobalFunctions.load_file_data",
                      :error => "failed to read file",
                      :incidentals => {"path" => path}
                      ).save
    end
    nil
  end

On Mon, Sep 27, 2010 at 7:15 PM, giorgio <[email protected]> wrote:

> Hi,
>
> I have used attachment_fu before with no real problems but I'm not
> sure if it is what I need now..
>
> I have an application that stores blobs (word documents, scanned
> documents etc) in the database.
> I want to convert it to store in S3.
>
> All the paperclip and attachment_fu examples deal with images and
> resizing and thumbnails etc etc which are not relevent in this case.
>
> Are they still the best options or should I just use the aws-s3 gem on
> its own?
>
> Ideally I'd like to just replace the database "content" column by
> saving to S3 as part of an AR callback and have an accessor on the
> model that retrievs the attachment only when requested...
>
> Anybody got any examples of something like that.
>
> Cheers
> George
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en.

Reply via email to