1

I am looking for gem do preview image before upload image to work in my application Ruby on Rails. Any suggestion ???

usama kabel
  • 11
  • 1
  • 4
  • This is possible with HTML5, see: http://stackoverflow.com/questions/14069421/in-html5-how-to-show-preview-of-image-before-upload – Arctodus Jul 05 '14 at 13:12

2 Answers2

2

There is a jQuery File Upload Plugin that includes preview functionality. And there is a rails wrapper for it too: https://github.com/tors/jquery-fileupload-rails. I use it successfully in my projects.

San
  • 1,954
  • 1
  • 14
  • 18
  • Found this gem called [Rails Uploader](https://github.com/superp/rails-uploader) which integrates [jQuery File Upload Plugin](https://github.com/blueimp/jQuery-File-Upload) with Rails forms to show preview in the form. – San Jul 13 '14 at 18:53
1

I'm not aware of any gems that package this up, but the JavaScript to create an image preview is very easy if your browser supports FileReader API (good browsers and IE 10+). Mozilla has a basic example here.

Wizard of Ogz
  • 12,543
  • 2
  • 41
  • 43
  • I am looking for gem to out of handling all browsers. – usama kabel Jul 05 '14 at 16:00
  • FileReader API is the best solution for the future and is already well supported (http://caniuse.com/filereader). If you need to support IE9 or earlier you will probably need something which relies on Adobe Flash because it is not possible to access local file data in that browser. To my knowledge no such gem exists which handles that. This problem really has nothing to do with Rails, so you are best off searching for a JavaScript library to help you. – Wizard of Ogz Jul 06 '14 at 04:16