aws - how to store the file details using s3_direct_upload - ruby-on-rails

In rails 4.0.2, I am using s3_direct_upload gem to upload files directly to s3, after that I want to store the files & convert it to html, also I want to store some dependency files like converted .html / .txt files back to s3. But I am not able to get the files from s3 & also it is not saving to the database.
I have referred this from http://blog.littleblimp.com/post/53942611764/direct-uploads-to-s3-with-rails-paperclip-and.
How can I overcome this problem? awaiting for the solution.

Related

Can I use zipline gem to download from s3 without model associations with paperclip or carrierwave

I want to allow my user to download a bundle of files that are stored on s3 using the zipline gem. The files are already hosted on an s3 server but they aren't there as part of a paperclip or carrierwave attachment in my app. Will I need to create some records in my database to sort of trick zipline into thinking they are paperclip attachments, or is there a way I can send the zip file without bothering with an attachment gem? At the moment, trying to download the files with zipline doesn't throw an error message at all. It just seems to skip right over and nothing downloads.
See the part of the zipline README where an enumerator gets used to include remote files into the ZIP. It uses absolute URLs, to generate those from your S3 objects you will need to use presigned URLs (which Zipline is going to pass on to Curb):
Aws::S3::Bucket.new(your_bucket_name).object(your_key).presigned_url(:get)

How can I upload a GarageBand (.band) file into my rails app?

I am creating a Rails app which should allow users to upload any type of audio file format. I am currently using Carrierwave gem to accomplish this, however CarrierWave will not allow uploads of certain file formats such as .band (GarageBand default format).
Is there a way to accomplish this?
Well, .band is actually a folder containing multiple files. So, yes, carrierwave does not allow uploads of folders. The folder must be converted into a .zip file.

Rake task creates CSV and then upload to S3. How?

I have a rake task that creates a CSV file. Right now I am storing this file into my /tmp folder (I am using Heroku). This CSV file is not associated with any model, it's just some data I pull from several APIs, combined with some data from my models.
I would like to download this file from Heroku, but this seems not possible. So, my question is: Which gem am I trying to look for in order to upload that file to Amazon S3? I have seen gems like Paperclip, but that seems to be associated with a model, and that is not my case. I just want to upload that CSV file that I will have in /tmp, into my Amazon S3 bucket.
Thanks
You can use aws-s3 gem
S3Object.store('filename_in_s3.txt', open("source_file.tmp"), 'bucket_name')
You should define the exact path of your tmp file, for example:
open("#{Rails.root}/tmp/source_file.tmp")
CarrierWave can directly interface your Ruby application with S3 directly via the Fog library. Rather than operating on the model level, CarrierWave utilizes a Uploader class where you can cull from across your APIs and datasources, which is precisely what you're trying to accomplish.

How should I parse a file in Ruby on Rails to store in a database?

I want to create a simple form for users to upload a file, which will be stored in a database. I also want to display all the submitted files in the database with their name and a link to download the file. Schematically, what's the best way to do this in Rails/how should I store the file in table (which fields should my table have? etc). Thanks!
i would use paperclip gem with the upload to s3 instead of file system
https://github.com/thoughtbot/paperclip
checkout the README, most of the examples are for an image, but works with non-image files as well
use paperclip to upload file, you can store images/file in your database as well as in s3 (AWS)
See below link how to use paperclip in rails with example
Here is the steps how to upload file using paperclip in rails
http://patshaughnessy.net/2009/4/30/paperclip-sample-app
for github
https://github.com/thoughtbot/paperclip
https://github.com/websymphony/Rails3-Paperclip-Uploadify

Uploading & Unzipping files to S3 through Rails hosted on Heroku?

I'd like to be able to upload a zip file to my Rails application that contains a number of images. Then I'd like Rails to unzip that file and attach the images inside to my Photo's model via Paperclip, so that they are ultimately stored on my Amazon S3 account (configured through Paperclip).
I'd like do do this all on my Rails site hosted on Heroku, which unfortunately doesn't allow local storage of any kind (so far as I'm aware) to temporarily do the unzipping before the Paperclip parsing.
How would I do this??
I would recommend uploading directly to S3 which bypasses Heroku entirely so you're not restricted to the 30 second request timeout they enforce (which drops your uploads after that time is hit) or the 1gb /tmp directory limit. After the file is uploaded, you can make a POST to your Rails app with the file's name and location and then do your unzipping operation. If you'd like to use Paperclip for post-processing, I have attached a link below. If you end up going the route of uploading directly to S3 which offloads the work from your Rails server, please check out my sample projects:
Sample project using Rails 3, Flash and MooTools-based FancyUploader to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-FancyUploader
Sample project using Rails 3, Flash/Silverlight/GoogleGears/BrowserPlus and jQuery-based Plupload to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-Plupload
Here is the link for the Paperclip post processing for an example like images:
http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip
dmagkic is correct about the rails_root/tmp. I recommend something like the following:
Upload files through heroku to S3
Setup a background job to zip the files (store the file names that you need to group)
run the BJ that downloads the files from S3, zips them, sends the zip to S3, removes the unzipped files.
That way your application will still be responsive'ish during the upload process.
If you try to upload multiple files, you COULD write to /tmp, but just make sure that all the files come across in the same post request.
Heroku does allow writing to #{RAILS_ROOT}/tmp.
But you need to take in mind that file will be there only as long as request lasts. Probably longer, but that is not guaranteed. You could try to block request while you unzip and send to S3, but you should take care of the time it takes.
It sounds to me like you need some flash uploader that can unzip and send to S3, without Heroku.

Resources