Search code examples
rubyamazon-s3sinatracarrierwavefog

Upload videos to Amazon S3 using ruby with sinatra


I am building an android app which has a backend written on ruby/sinatra. The data from the android app is coming in the form of json data. The database being used is mongodb.

I am able to catch the data on the backend. Now what I want to do is to upload a video on Amazon S3 being sent from the android app in the form of byte array. I also want to store the video in a form of a string in the local database. I have been using carrierwave, fog and carrierwave-mongoid gems but didn't have any luck.

These are the some blogs I followed:

https://blog.engineyard.com/2011/a-gentle-introduction-to-carrierwave/

http://www.javahabit.com/2012/06/03/saving-files-in-amazon-s3-using-carrierwave-and-fog-gem/

If someone could just guide me with how to go about it specifically with sinatra and mongodb cause that's where I am facing the main issue.


Solution

  • You might think about using AWS SDK for Android to directly upload to S3 so that your app server thread doesn't get stuck while an user is uploading a file. If you are using a service like Heroku you would be paying extra $$$ just because your user had a lousy connection.

    However in this scenario;

    Uploading to S3 should be straight forward once you have your mounting in place using carrierwave.

    You should never store your video in the database as it will slow you down! DBs are not optimised for files, OSs are. Video is binary data and cannot be stored as text, you would need a blob type if you want to do this crime.

    IMO, uploading to S3 is good enough as then you can use Amazon cloudfront CDN services to copy and distribute your content in a more optimised way.