Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A good pattern to use is to upload the file directly to Amazon s3 and then add it into your app with Carrierwave from that location. If you store the file in a temporary bucket/location on s3, you can then have carrierwave effectively process then move it. After it is directly uploaded to s3, and assuming you have available the bucket and address you uploaded it to, you can use code like this to have Carrierwave pick it up, process it, and "move" it:</p> <pre><code> def add_file_from_URL(bucket, object_address) s3 = AWS::S3::new bucket = s3.buckets[bucket] object = bucket.objects[object_address] object_url = object.url_for(:read, :expires =&gt; 60*60, :secure =&gt; true) #expires in 1 hour self.remote_attachment_url = object_url.to_s self.save object.delete() end </code></pre> <p>This code would go in your model that has the file within it.</p> <p>I have left out the code to process (resize) the file, as you should be able to find that within the Carrierwave docs easily if you don't already have that part done.</p> <p>To keep track of meta data for the file I would suggest use a :before_save callback to store this information in fields along side the file. You would have a method like this:</p> <pre><code> private def update_file_attributes if file.present? self.file_content_type = attachment.file.content_type self.file_size = attachment.file.size end end </code></pre> <p>In this example, I am saving the actual file size, but you could tweak this for dimensions instead. This goes in the model that you save the file in.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload