Rails preview for active storage videos not working - ruby-on-rails

I have a pretty standard model where you can upload videos - so far so good.
The video gets uploaded and is also displayed on the show view. Alle seems to be fine....but:
I cannot get a preview fo to work.
ActiveStorage::Blob.last.previewable?
--> false
ActiveStorage::Blob.video?
--> true
FFMPEG is installed on the system and in the gem file
which ffmpeg
--> /usr/local/bin/ffmpeg
gem 'streamio-ffmpeg'
And of course if I run preview directly, I get an error
ActiveStorage::Blob.last.preview(resize: "200x200>").processed
--> ActiveStorage::UnpreviewableError (ActiveStorage::UnpreviewableError)
Previewers is having video included
Rails.application.config.active_storage.previewers
--> [ActiveStorage::Previewer::PopplerPDFPreviewer, ActiveStorage::Previewer::MuPDFPreviewer, ActiveStorage::Previewer::VideoPreviewer]
I also tried different video formats, but nothing works and I am out of ideas where to look.
Anybody had the same issue?

I had face the same issue, please follow the below step which might help you because it work for me.
install the ffmpeg
install the ImageMagick
attribute :video_preview do |object|
Rails.application.routes.url_helpers.rails_representation_url(object.video.preview(resize: "200x200").processed, only_path: true)
end
use this method to check whether is working or not.

I had a similar problem of video previews working fine locally but not playing in production. It was simply because I hadn't installed ffmpeg in my production environment.
My production environment was heroku, so I simply added the ffmpeg buildpack like so:
heroku buildpacks:add --index 1 https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
And then everything worked as expected.

Related

Loading ActionText::Attachable from identical SGID no longer works after restoring database

I'm using ActionText and embedding IFRAME for things like YouTube and Spotify embeds. It's working great! Here's what it looks like when I render the HTML (this is for a Spotify embed as you can see):
<action-text-attachment sgid="BAh7CEkiCGdpZAY6BkVUSSIoZ2lkOi8vYmxvZ2xpbmUvU3BvdGlmeS8xP2V4cGlyZXNfaW4GOwBUSSIMcHVycG9zZQY7AFRJIg9hdHRhY2hhYmxlBjsAVEkiD2V4cGlyZXNfYXQGOwBUMA==--fcc8035346e616846f2068f52f685d2feb3b30e2" content-type="application/octet-stream"><div class="embed-responsive embed-responsive-16by9">
<iframe width="300" height="380" title="Spotify Embed: American Head" src="https://open.spotify.com/embed/album/4H8NX3ovAZdY2iJmwSNqlw?si=cf4XXoavSAynCBOvqltSHw"></iframe>
</div>
</action-text-attachment>
I have recently exported the database (from Heroku) and restored it to another VPS provider. That worked fine for my ActiveStorage blobs (images etc) but the embeds are no longer working. The above example, despite having the same SGID now looks like this:
<action-text-attachment sgid="BAh7CEkiCGdpZAY6BkVUSSIoZ2lkOi8vYmxvZ2xpbmUvU3BvdGlmeS8xP2V4cGlyZXNfaW4GOwBUSSIMcHVycG9zZQY7AFRJIg9hdHRhY2hhYmxlBjsAVEkiD2V4cGlyZXNfYXQGOwBUMA==--fcc8035346e616846f2068f52f685d2feb3b30e2" content-type="application/octet-stream">☒</action-text-attachment>
On my Heroku console I can load the model using:
SignedGlobalID.find("BAh7CEkiCGdpZAY6BkVUSSIoZ2lkOi8vYmxvZ2xpbmUvU3BvdGlmeS8xP2V4cGlyZXNfaW4GOwBUSSIMcHVycG9zZQY7AFRJIg9hdHRhY2hhYmxlBjsAVEkiD2V4cGl
yZXNfYXQGOwBUMA==--fcc8035346e616846f2068f52f685d2feb3b30e2", for: "attachable")
This works and returns the associated ActiveRecord model. However, running the same command when connected to my restored database results in nil
I wondered if anyone was able to shed any light on this?
I have narrowed the issue down to an InvalidSignature message. For example, on Heroku I see this:
SignedGlobalID.send(:pick_verifier, for: "attachable").verify(node["sgid"])
=> {"gid"=>"gid://myapp/Spotify/1?expires_in", "purpose"=>"attachable", "expires_at"=>nil}
Where's locally, if I run it:
ActiveSupport::MessageVerifier::InvalidSignature (ActiveSupport::MessageVerifier::InvalidSignature)
Could it be because the secret on one server is different from the other? If so, what is the correct way to go about doing this so that the SGIDs are 'portable' across servers?
I'm running Rails 6.1 alpha.
Ok, apologies but it turns out that despite Rails.application.credentials.secret_key_base being defined the same on both servers, one of them (Heroku) had also defined a different SECRET_KEY_BASE environment variable which seems to take precedence. Once I define this on the new sever, the SGID works fine.

pdf.js gem producing errors

I am a rails novice and trying to create my web portfolio in Cloud9. I wanted to display my resume.pdf in the user browser so I installed this gem gem 'pdfjs_rails' now my app doesn't even start in cloud 9. It show the following error messages in the terminal:
Please help me. How can i revert it back? thanks
Doesn't look like anything related to pdfjs (no point in that direction). Are you sure you've selected the right runner in Cloud9? See:
https://community.c9.io/t/error-when-running-ruby-project/11799/4
More in general: if you think an issue would be related to a gem, you can simply remove it from the Gemfile and run gem bundle to 'revert' to a previous state.

HTML video background with Ruby on Rails

I am a beginner on Ruby on rails and I am building an application in which have a Video Header Background. The application works fine locally, but once I tried to upload it to Heroku the video-background does not play.
The app is still in development.
I get in my Web-browser console the following messages:
HTTP load failed with status 404. Load of media resource https://serene-fortress-58125.herokuapp.com/assets/Islands.mp4 failed.
All candidate resources failed to load. Media load paused.
I am thinking that I should host the video in some sort of hosting service to make it available to the Heroku app, but I need to figure out how that could work with my current html code and which hosting service to use. I tried with tinypic to host the video, but the video was played as x-shockwave-flash and not compatible with my current web design.
I was thinking of using the tubular jquery plug in as adviced in the following post and using Youtube as host:
Fullscreen video background - <video> vs YouTube/Vimeo-<iframe>?
I would maybe need a couple of advices on how to use jquery with Ruby on Rails 5.0.1 and what would be the best practice to make this work out. Any advice would be really helpful.
Thanks a lot
Fabrizio
This is my app on Heroku:
https://serene-fortress-58125.herokuapp.com/
This is my git:
https://github.com/fabriziobertoglio1987/portfolio
This are links to similar unanswered questions on Stackoverflow:
adding an animated background to a ruby on rails app
https://stackoverflow.com/questions/35319525/ruby-on-rails-html5-video-as-background-for-landing-page-not-loading-on-heroku
The 404 error message is because i needed to use the rails video_tags and not the html tags. I was helped from a friend in finding the solution, the following document helped.
https://devcenter.heroku.com/articles/rails-4-asset-pipeline

Newly uploaded images break in production but not in development

I would appreciate any feedback regarding what may be causing my issue, described below.
I have an application that allows users to upload images. Everything works fine in development and used to work fine in production.
Recently, my newer images have all broken. I can upload new images, but when I check back a few hours later, the images are broken again. This started happening about a week ago, and images that I've had up in production from before then are still ok.
I am using Rails with Bootstrap and SimpleForm, and using Paperclip for the images. I am using Postgres in both devleopment and production, and am deploying to Heroku.
The only hint I have is in the "blank_profile_pic.png" image that I use as a default when users don't have a profile picture uploaded.
User.all.each do |u|
if u.profile_pic.file?
image_tag(user.profile_pic)
else
image_tag("blank_profile_pic.png")
end
end
For users that don't have a profile_pic uploaded, a broken image appears if their profile was created in the last week, but the expected "blank_profile_pic.png" remains for people that created their account before the issues started surfacing a week ago. How can the same block of code return different results between recent and older users?
I really don't know where to start with this, so would appreciate any feedback regarding what possible causes could be, and if there are any other files that I can show here.
Thanks very much for your help!
Heroku is a read only system. So you most definitely have to upload your images either to S3 or some other cloud provided.
Your images might have been uploaded to /tmp in Heroku and then somehow it was cleared, hence the errors.
Here are the docs: https://devcenter.heroku.com/articles/read-only-filesystem
And configuring Paperclip with S3: https://github.com/thoughtbot/paperclip#storage
I am not sure if you have the imagemagick gem installed, but we had same issue with image_magic that was breaking our paperclip functionality in production, but not in development (weird, I know). Yet even after removing imagemagick from our gemfile and Gemfile.lock locally (running bundle install and all that stuff) and then deploying back to production on heroku, the error persisted in production! (weird, I know).
What ended up doing the trick was running:
$ heroku repo:purge_cache -a myAppName
(Taken from: https://github.com/heroku/heroku-repo#purge_cache)
When you deploy your app, Heroku caches some things like your assets and installed gems in order to speed up deployment. Although this is a great feature, it can have side-effects sometimes, and in this case, it seems that something about the imagemagick gem got "stuck" in production's cache, which is why purging solved the issue for us (since after purging, your app will rebuild itself from scratch on your next deployment)

Displaying image generated by Paperclip in Rails app

I am able to display image generated by Paperclip in Rails app, at DEVELOPMENT env,
E.g http://localhost:3000/system/shot/sample.png
However upon I migrate to PRODUCTION, http://xyz/system/shot/sample.png is not recognized. I am using Passanger running on Apache. Is there any config that I need to setup at prod env?
And I've verified the physical folder and file exits at prod machine.
Note: i just check the production.log , and herewith the error
**ActionController::RoutingError (No route matches [GET] "/system/shot/sample.png"):**
Looking at the error above, likely I need to do something in route.rb ; but strangely i am using same route.rb in DEV , and it works..
Thanks in advance.
do something like which convert and it should print out something. if there is nothing, then you know you need imagemagick.
Check that your imagemagick on your slice is set up to serve png's and jpgs too, while you are at it.
I use Gentoo and the built in package manager use flags turn off that stuff, so my pngs never showed.
sorry, it is false alarm, the image file was not yet created initially.

Resources