Carrierwave file upload w/ resque job to upload to S3 - ruby-on-rails

What would be the best solution to upload files to file storage, upload to S3 (via Resque), and then modify the storage type for carrierwave on the record? Is this possible?
Thanks!

You could try the carrierwave_backgrounder gem which has Resque support for uploading files to S3 in the background after the file has hit your server.
Alternatively you could try uploading directly to S3 from the user's browser using the new CORS support. Eg. s3_direct_upload

Related

Unable to retrieve user-uploaded audio files from S3 using Rails Active Storage

Brief Background
I have a Rails web application that allows users to upload an avatar and audio files. The app stores, retrieves, and displays/plays this media back to the user once it is uploaded. The web app is hosted on Amazon Elastic Beanstalk, and I'm using Rails ActiveStorage to store the uploaded files to Amazon S3. I'm using a Postgres Amazon RDS database generated through my Elastic Beanstalk instance to handle all other (non-media) storage.
Problem
In production, a user can upload image and audio files to S3 using the web app, but calling the ActiveStorage service_url method to retrieve these files from S3 only works for images (no URL is found/generated for successfully uploaded audio files, even though ActiveStorage was used to upload the files to S3).
What I've Tried
I've pointed my dev environment to S3 to see if audio upload and retrieval works when I run the server locally, and it works perfectly! A user is able to upload an audio file to S3 and retrieve that file from S3 using the ActiveStorage service_url method. With this change, my dev and production configurations are almost identical, so I'm wondering if there's some extra configuration I need to do for Beanstalk, S3 or maybe even Nginx to make ActiveStorage work for retrieving audio stored in S3 in production?

How to delete a file from the server using Fog and Carrierwave after it's being downloaded?

Im using Carrierwave and Fog to upload a temporary file to S3. I then use fog_authenticated_url_expiration to give a expiring url to the use. After the user download this file, I want to remove it from S3. How can I do this?

How to create multipart upload to s3 (Rails)

is there any gem/ plugin or any refference to create multipart upload to s3 in Ruby on Rails?
ref : http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingRESTAPImpUpload.html
I wish to create upload very large file and need to seperate it.
I think you can try this plugin for uploading files directly to the amazon s3. I am going to use it in my the current project.
Carrierwave Direct

Paperclip: migrating from file system storage to Amazon S3

I have a RoR website, where users can upload photos. I use paperclip gem to upload the photos and store them on the server as files. I am planning to move to Amazon S3 for storing the photos. I need to move all my existing photos from server to Amazon S3. Can someone tell me the best way for moving the photos. Thanks !
You'll want to log into your AWS Console and create a bucket structure to facilitate your images. Neither S3 nor Paperclip have any tools in the way of bulk migrations from file system -> s3, you'll need to use the tool s3cmd for that. In particular, you're interested in the s3cmd sync command, something along the lines of:
s3cmd sync ./public/system/images/ s3://imagesbucket
If you have any image urls hard-coded into your database (a la markdown/template code) this might be a little tricky. One option would be to manually update your urls to point to the new bucket. Alternatively, you can rack-rewrite.
You can easily do this by creating a bucket on Amazon S3 that has the same folder structure as your public directory on your Rails app.
So say for instance, you create a new bucket on Amazon S3 called MyBucket and it has a folder in it called images. You'd just move all of your images within your Rails app's images folder over to that new bucket's images folder.
Then you can set up your app to use an asset host like this answer describes: is it good to use S3 for Rails "public/images" and there an easy way to do it?
If you are using image_tag or other tag helpers (javascripts, stylesheets, etc), then it will use that asset_host for production environments and properly generate the URL to your S3 bucket.
I found this script which takes care of moving the images to Amazon S3 bucket using rake task.
https://gist.github.com/924617

Rails: How can I edit text files stored on Amazon S3?

I'm using paperclip to upload some text/csv files to an S3 bucket.
I need to edit those files occasionally. How can I edit and re-save those?
Before using S3, I was just using File.open for saving the files, but that throws a "No such file or directory" error now.
File.open opens a file system object. To access S3 you need to connect to the S3 server and issue commands, such as GET.
There are some gems available from the Amazon developer's site which may help.
http://aws.amazon.com/ruby/

Resources