ActiveStorage::UnpreviewableError - ruby-on-rails

I'm trying to create a PDF preview for my PDF files, but I don't know where to start, I'm using poppler gem on Ruby on Rails.
The app is giving me this message: "ActiveStorage::UnpreviewableError in Tasks#show"
So I'm not understanding where should I need to declare the preview
Looking on google I found several sites with methods, but I don't know where to add this code, I've tried by creating a new folder on the app directory, but this didn't work.

In activestorage documentation says about requirements to use this feature.
libvips v8.6+ or ImageMagick for image analysis and transformations
ffmpeg v3.4+ for video previews and ffprobe for video/audio analysis
poppler or muPDF for PDF previews
Check if in your environment has the requirements

Thanks for the advice, I realized I haven't installed muPDF on my environment, the thing that worked for me was to install it from the home directory (outside my project) and that's it, now the preview is working perfectly fine.
https://ubuntuhandbook.org/index.php/2018/05/install-mupdf-1-3-0-ubuntu-18-04/

Related

How to use tensorflow in rails?

Tensorflow does not officially support Ruby. I was wondering how one can use tensorflow, full version (Python or JS), in a rails app.
While this is a general question, the answer may be of use to the community. No one has asked this and many people new to using other languages like Python in Rails would benefit.
Another way to state this question is what some of the successful companies using rails are doing to use tensorflow.
I'm only going by its readme, but the tensorflow ruby gem appears to be well supported.
This post shows how to use it to classify images
(I take directly from the article here)
Steps:
Clone and install tensorflow.rb
Go to image directory
Download this zip file from google
extract the file ‘tensorflow_inception_graph.pb’ in this directory.
Do ruby classify_image.rb (This will work on the default image of the Mysore palace).
To try this out on your own images you can add the image to this directory and then change file name in line 31 on classify_image.rb .

Rails 4: preview image before upload gem

I am looking for gem do preview image before upload image to work in my application Ruby on Rails.
Any suggestion ???
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.
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.

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.

get some metadata about a video file

I am currently working on a rails application in which the user upload a video file on the server, after what I send it to S3 where it's encoded by another service.
The thing is that before uploading it to S3 I need to know the quality of this file, the resolution, the bitrate, ...
I saw that the rvideo gem can do that but I'd like to avoid having to install ffmpeg on my rails server.
So my question is do you see a way to do that without much dependency ?
Thanks,
UPDATE: I also saw 2 gems wrapping the MediaInfo CLI but same problem I'd like to avoid installing MediaInfo CLI on my rails servers
You should be able to use the inspect command available in unix. I know paperclip uses it with their photo processing.

Resources