Uploading an image to a Rails server via an Ember.js app - ruby-on-rails

Like it says on the tin, I'm trying to upload an image with my Ember.js app to a Rails backend that's using Paperclip to manage file uploads. I had a look around and couldn't see any simple way to do this, does anyone know of a good solution here?

I faced similar recently, and it turns out that there are lots of complications with file uploading - does the device support it, do you want to be able to style the input that triggers the upload, etc.
We opted for Jquery File Upload: https://github.com/blueimp/jQuery-File-Upload
The approach I took was to upload directly to S3 from the browser, and then set the token that S3 returns as a property on a model, then save that to the server. Then on the server, you set off a background job to pull in that file from S3 and put it where it should be.

I wrote a fairly simple ember.js file upload example a few months back that shows how you can write a custom view + a custom adapter that allows you to post a multipart form back to the server. The example I did is built for python / django but the concepts should apply
https://github.com/toranb/ember-file-upload
I recently upgraded this to RC1 (like 5 minutes ago) and it appears to still work :D

There is now an Ember Uploader plugin for Ember. I'm just in the process of integrating it right now.
I have a couple kinks I'm ironing out, but it seems pretty legit. Probably less configuration than using the jquery file upload.

Related

text editor to support uploading image from client rails app to rails api using ckeditor

I have created an CMS API and admin_client app with active resource in rails 4.1.9. Everything is working fine, Now I need a text_editor with image uploading feature in my admin_client app which get stored in CMS API. For that I decided to use "CKEditor" gem.
my question is
whether i can install the gem in both my API(for storing the image and for serving the image to user_client app) and admin_client app(for UI purpose).
Can i install the gem only in my API(for storing the image and for serving the image to user_client app). And use CKEditor plugin in my admin_client(for UI purpose).
Is there any other gem or options to achieve this ?
Please suggest me one of the options to achieve this.
I'm not sure as to the specifics of your request, but I do have experience with CKEditor, so I'll write some musings for you:
--
Install the gem where it's going to be deployed (the JS used)
Yes, but you have to match the models
CKEditor does it well with Paperclip - I'd stick with CKEditor if I were you.
CKEditor's rails gem allows you to use Paperclip to upload the images. We had Paperclip installed anyway, so there was no problem. You may have to install it separately.
When you install Paperclip, you'll get several models:
/ckeditor/asset.rb
/ckeditor/picture.rb
/ckeditor/attachment_file.rb
These are to be put into your backend app (I'm not sure whether that's your API or front-end view) (the generator will do this). This will then give you the ability to save images from your CKEditor.
We have totally changed our models - so I can tell you it works out of the box, as well as if you customize. It's no problem if you want to keep them as they are when put onto your system.
Here's an example of one of our altered models (we have a central table for our assets):
--
The trick will be to make sure your CKEditor instance is able to send the correct assets to your API / backend app.
Since you've not published any code, I can only give you this broad information. If you post some specifics, I may be able to provide more detail if you need it

How might I be able to link jquery file upload, ajax, and jquery file download on rails?

Thanks!
I'm a complete beginner but I'd like to know even in a generic way so that my users could upload a file to another user's directory, the file gets saved on to a server and the receiving user could download it when the upload gets finished.
Since you're a complete beginner, I won't give you a lot of code; instead, I'll show you the overview of what you can do, and hopefully that will give you a much more refined approach to adopt:
Rails Uploads Using Paperclip
What makes Rails so powerful is the gem ecosystem - these are little plugins which give you functionality outside the scope of the Rails framework. You can get Gems for everything from file uploads to CSS frameworks - all for free
One of the most important & popular gems for Rails is Paperclip (and you have Carrierwave which also does the same job). These are what you use to process image uploads in Rails
Since you're a total beginner, you should really watch this Railscast about how to upload files with Rails using Paperclip:
There are also a lot of other tutorials on Paperclip:
Heroku's Paperclip Tutorial
Simple Paperclip tutorial
Another Paperclup tutorial
I would write some more updates about Paperclip & JQuery, but I think you should get your head around the upload process first

Creating PDF from photos on a Facebook Rails app

I'm creating a Facebook app using Rails and hosted on Heroku and I'm having a bit of trouble finding the ideal way to solve a problem. I want the user to be able to move their photos around on the screen, position them, and then download that as either a PDF or a PNG file to be emailed or printed. I have the app getting the user's facebook photos and they can drag them on to a HTML5 Canvas element to position them. Taking this canvas, however, and converting it into something printable is where I'm hitting a dead end.
Basically I have a few ideas I have tried:
Convert the Canvas to a PNG using toDataURL() - Would work perfectly but since the photos are external, the canvas is "dirty" and will throw up a security issue. I've thought about trying to copy the pixels of each image to a pixel array but I've heard this may not work either due to security issues. Since the app is dealing with people's facebook images I really don't want to store them on the app's server.
Use PDFKit/wkhtmltopdf to create a PDF using Rails - I've tried this, but since the app is a Sinatra app (I think), it's confusing me a lot. It's throwing errors with the to_pdf call saying 'Command Failed'. I've tried adding a config.middleware.use line but I'm not 100% sure where to put it and everywhere seems to be failing saying "config" is an undefined variable. Also installing wkhtmltopdf seems to fail on Heroku once I test it outside localhost.
Use Prawn to create a PDF using Rails - I've tried prawn but it seems to have a similar problem to PDFKit and I get confused about what goes where on a Sinatra app. I'm sure I read as well that people were having problems with it too.
Have I missed any obvious solutions to this, or is there something I'm not thinking of? All I want to do is create some kind of easily printable file with positioning intact that can be easily downloaded and printed by the user but I've come across so many problems that I don't know where to go next and I'm going round in circles.
If anyone had any advice for me about how I could get around this problem I'd really appreciate it.
if prawn is giving you grief just use one of the jquery plugins to print your div content. You could even configure a pdf printer and print the document instead of hard copy if you so wish/need images in pdf format.
I use http://archive.plugins.jquery.com/project/jqPrint plugin in one of my projects and it works like a charm.
It sounds like many of your issues relate to the necessary PDF binaries not being accessible on Heroku. In following with the twelve factor approach to dependency isolation Heroku purposely provides a very bare system.
If you need to run a custom binary on Heroku I'd suggest looking at a tool called Vulcan which can compile a binary that's compatible with the Heroku runtime.

uploading a file with rail - what is the best approach

I have a requirement of uploading a file to my disk through my webpage. Seems like I have two options
My requirement is specific that I will upload ONLY text files.
Using default rails methods to upload a file.
Ex: http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm
Using a plugin like 'PaperClip'
Following are my concerns:
I want to keep the file upload as simple as possible
Keep as away as dependencies like Imagemagic etc
I'm using rails 2.8.3
concurrent file uploads can be happen by multiple users
please can someone tell me what are the pros and cons of having
writing a simple file upload (option 1)
using a plugin/gem to upload a files
Writing your own file uploader is an option, but using a pre-built gem provides you with all of the code you need, straight after install.
Gems will usually have all of the functionality packaged into them that handles all of the cross-platform issues and security headaches your likely to run into by writing something from scratch. A well maintained gem will also have a good community behind it, keeping things up to date.
The popular Gems out there are really easy to use, and unless you are resizing images etc, you shouldn't need ImageMagick installed. Have a look at these:
http://railscasts.com/episodes/134-paperclip
https://github.com/technoweenie/attachment_fu/wiki
Paperclip is far easier to build a simple upload form with, but I'm not sure if it works on Rails 2. Attachment_fu is an old favorite from the Rails 2 days and will definitely be able to handle your problem, it just requires a little more configuration.

Paperclip, large file uploads, and AWS

So, I'm using Paperclip and AWS-S3, which is awesome. And it works great. Just one problem, though: I need to upload really large files. As in over 50 Megabytes. And so, nginx dies. So apparently Paperclip stores things to disk before going to S3?
I found this really cool article, but it also seems to be going to disk first, and then doing everything else in the background.
Ideally, I'd be able to upload the file in the background... I have a small amount of experience doing this with PHP, but nothing with Rails as of yet. Could anyone point me in a general direction, even?
You can bypass the server entirely and upload directly to S3 which will prevent the timeout. The same thing happens on Heroku. If you are using Rails 3, 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
By the way, you can do post-processing with Paperclip using something like this blog post (that Nico wrote) describes:
http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip
Maybe you have to increase the timeout in the ngix configs?
You might be interested in my post here:
http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip
Its about uploading multiple files (with progress bars, simultaneously) directly to S3 without hitting the server.
I was having a similar problem but with using paperclip, passenger and apache.
Like nginx, apache has a Timeout directive in apache which I increased to solve my problem.
Also there's an interesting thing passenger does when uploading large files.
Anything over 8k is written to /tmp/passenger. and if apache doesn't have
permissions to write there you get 500 errors also.
Here's the article.
http://tinyw.in/fwVB

Resources