ReactJS and AWS-S3 Upload from the client side - ruby-on-rails

I have a single page application built with ReactJS and MobX for the front end part, and ruby on rails for the backend part. I have an image drop zone container, and I want the user to be able to upload images, but all the uploading implementation to be done in the front-end part, and the backend only will receive the URL from the uploaded image. Is it possible to accomplish this with ReactJS without involving the server at all?

Yes there is a concept called as direct upload which you can use to do this. Here is an article by heroku to do this https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails
You can also look into the gem carrierwave direct https://github.com/dwilkie/carrierwave_direct
You might also want to check out http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Presigner.html
and
https://www.npmjs.com/package/react-s3-uploader
If you are willing to use a easy to use managed service filestack.com is a good option.

Related

Scaling user image uploads on Heroku with Carrierwave

I have a Rails app on Heroku that seems to be having trouble scaling the way I want it to. In the app, a user can upload multiple nested images to an invoice. Based on my research, it seems that this ties up a Heroku web dyno (I'm running 3) until it's done uploading. I've looked into Carrierwave Direct so that a web dyno isn't used but it doesn't seem that this is compatible with a nested model. Does anyone have any other suggestions?
Don't upload images to Heroku. It will lock your entire web server. Instead, use a jQuery library (https://github.com/blueimp/jQuery-File-Upload) to upload directly to Amazon S3 from the client side.

iOS Client + Rest API to upload photos

I have a basic requirement of uploading an image from an iOS App to a remote server. I know that I can use NSURLConnection to transfer the image to a remote server but I need to develop a REST Webservice also in the remote server which can accept images from the iOS Client and store inside a DB/hard disk .
Can anyone please suggest me the best method/libraries which can be used to to develop the REST Webservice .
I'd recommend using Ruby on Rails with the Paperclip gem.
If it's completely new to you, you can start with the Guides.
There's a lot of material on how to build a RESTful API with Rails, like this screencast.
Once you've understood how to develop an API, and how to use Paperclip to save images on the server, the answer to this question might help you with the file upload part.

How to upload an image to another server via HTTP post using carrierwave(Ruby On Rails)?

I am trying to upload an image to another server via HTTP post using carrierwave? What I understand so far is, Carrierwave supports some known cloud storage. but, in our application, we have a separate storage system with MongoDB. In order to store any file in that server, we can use HTTP post. Now, I am trying to write a client code to upload image. Is it possible to achieve by using Carrierwave or is there any other gem available?
Thanks in advance.
If you're using CarrierWave and MongoDB, I would use the https://github.com/jnicklas/carrierwave-mongoid gem to connect and store directory in GridFS.
Here's a good post on uploading and retrieving an image via carrier wave and gridfs: http://hafizbadrie.wordpress.com/2011/04/14/image-upload-with-carrierwave-and-mongoid-gridfs-mongodb-in-rails-3/
you need to provide your data where there is s3 data in the tutorials:
stack overflow

Setting up a file server for integration with iOS apps

I need to set up a server so that files can be uploaded from an iOS app. I don't know how best to proceed. I thought about FTP but not sure if there is a better option.
any ideas appreciated
GC
Also I must add that I will be building the iOS app so can use server APIs in my code.
It's not ideal to set up a blind File/FTP server and hardcode the details into your app because all it takes is one person to intercept the login details and they have access to your server where they can upload (and potentially execute) bad things.
A possible idea could be to set up an API frontend on your server in a language of your choice (PHP, Ruby, Python or similar) where you can 'POST' images to the server. With the API frontend, you can also do validation to ensure that only valid images are being uploaded and all nefarious stuff is thrown away. Then, in your iOS app, you can set up code to interact with your API frontend and send the actual images which will then be stored on your server.
This is a fairly conceptual idea rather than an absolute implementation idea. It does require some thinking/reading and more setup/coding on the server side.
Edit: Just to add, if you only want a central location to store/get your images without controlling it on a per user basis then you may want to look into Amazon S3 as a File Server.

File storage backend for Rails

I have a Rails application that I want to add file upload to, so that the users have access to a "resources" section where they can upload and share (although not publicly) any type of file. I know I could build a solution using paperclip and S3 for example, but to try and avoid the admin overhead of all that I'm looking at API interfaces to drop.io and box.net. Does anyone have any experience of these? I've got a basic demo working rather well to drop.io, but I was just wondering if anyone had any better ideas or experiences.
Many thanks
D
I use attachment_fu with S3 backend. For User Interface goodness, I use YUI's file uploader.
Some of the files are uploaded with world read access, others with no public read access.
I use Attachement_fu to create self-signed urls to enable clients to access the private S3 files.
I did write some small helper routines for the S3 library for re-connecting after a timeout, handling various errors that the S3 library can raise, etc.
Building your own library for drop.io and/or box.net
Your idea of using the API for a commercial service is interesting but I haven't run into any problems with the above config. And the price for direct S3 access is very low.
If you do decide to go this route, you may want to open source your code. You'd benefit by getting testing, ideas, and possible code contributions from the community.
Note that if you have a lot of uploads, you can end up with a performance issue if the uploads are synchronous with the Rails thread--the rails process is busy uploading and can't do anything else until the upload is done.
HTH,
Larry

Resources