Images tags not showing in wicked_pdf gem - ruby-on-rails

I have a rails app, in which i store some images in AWS, and show them in a PDF report. When there is no images to be shown, i show a placeholder, like this one here: .
The problem is: the image is not show in the PDF file. When in debug mode, the image is shown as usual, but never in my PDF! The link to the image is like this: https://dl.dropboxusercontent.com/u/4096865/missing.png
Edit 1:
I tried to include the image like this: image_tag("https://dl.dropboxusercontent.com/u/4096865/missing.png")
The solution i've found was simple, but prevented me from using dropbox for storage: it must be a http url. So, when i uploaded it to AWS S3, it worked!
So, this here works perfectly: image_tag("http://s3-sa-east-1.amazonaws.com/base-fisc-prod/missing.png")

This is an issue with images stored in a HTTPS link, the easiest way to solve this is to store the images in a HTTP link.
If you must store them in HTTPS, use this solution provided here

Related

Active Storage: filenames with special characters

In my application, users can change the background image of a banner. They upload the file using Simple Form and Active Storage. It's working correctly but we had a user trying to upload a file name banner-website.png (2).png. The file is uploaded and saved but doesn't appear as a background image. I guess this happens because of special characters in the filename.
What is recommended to avoid such situations? Do we need to sanitize file names?
Several things to check:
Check the console and tried to view the CSS and see if the full link
is being populated? Try checking the CSS code and copy the link to
an address bar to see if the image loads from that direction.
Check the users png file to make sure its not corrupt. PNG headers that are corrupt can cause issues displaying in a website.
Check to see if your sanitizing plugin is causing an issue with that file. I have never used that one so regarding that I cannot say.
I tried uploading a file with a same name into my Rails 6 testbench (vanilla with active storage and stimulus js) and it works fine. It could be a conflicting CSS code too.
Just my 2 cents.
I've found the solution here: Rails Active Storage - Background Image invalid property?
Adding a single quote around the URL solved it.

WickedPDF shows only grey dot when loading image from S3 in Rails 5

In my Rails app my users can upload images via carrierwave and image magic. Works great.
Now I am trying to generate a PDF with the image so in my download.pdf.erb I have
<%= wicked_pdf_image_tag('https://s3.eu-central-1.amazonaws.com/bucketname/uploads/image/image/1/thumb_71fxg4BPTuL._SY450_.jpg') %>
In my browser I can access the URL and see the image but in my PDF file on production mode I only see a grey dot. On AWS the permission for the bucket and image are all public.
On my local server the PDF loads with the image.
Any ideas?
I solved and, although it's a workaround at might compromise the security of the app, here is what I did:
My app serves via HTTPS but still, removing the HTTPS from the S3 files solved the problem.
image_url.gsub('https','http')

AWS S3 not showing images on heroku?

I built a rails app and set up s3 and paperclip together. So far, the images are being posted into my s3 account. But on the live app it's not actually showing the image and just showing the broken file icon.
Any ideas why this is happening? Is it a paperclip error? is it Heroku? Is it my controller?
Here's the live app: http://petaluma-marin.herokuapp.com/Nutrition-Recipes
Here's my repo: https://github.com/Gcamara14/Recipe_app
Thanks!!
Your url to the images is wrong. The URL for your second image currently is this
http://s3.amazonaws.com/recipe-app-gio/recipes/images/000/000/009/medium/Screen_Shot_2017-05-30_at_1.19.49_PM.png?1496243164
What it needs to be is this
http://s3-us-west-1.amazonaws.com/recipe-app-gio/recipes/images/000/000/009/medium/Screen_Shot_2017-05-30_at_1.19.49_PM.png?1496243164
Notice instead of http://s3.aws... at the beginning you need http://s3-us-west-1.aws...
Whenever I have issues with S3 I find it is easiest to go to the bucket and look at the path and then inspect the image or asset and see if they match.
To give you a hint about what the issue might be, in your browser if you copy/paste the url for a photo you should see this message:
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
Take a look at your paperclip_defaults. You are missing the s3_host_name that would contain something like s3-us-west-1 (as mentioned in one of the prior answers).
Also looks like there is an issue already created in the paperclip repo that should help you out (here).

How should I upload text with images Swift

I am tryin got upload a document/textView with images to my server...
Now I am trying to figure out what would be the best way:
1) You can add the images 1 by 1 to UITextView and lower the quality and upload the whole textView NSAtributedString as a NSData file or a .txt file, and then decode it when downloading.
2) While adding the images to the UITextView I upload them to the server and store a URL link to the images in the UITextView in the same place of the image, and before upload the text with the url's I convert that all to HTML and then display that in a UIWebView.
Now first option seems to be the easiest to setup, but not neccessarily the quickiest, as the final file you upload could be 2-10 mb with roughly 5-7 images with a basic quality....
Now the second option is done in app's like WordPress, and looking at they're code on github Github WordPress Keyboard they convert it differently to html using "libxml2" and store the url for the image when adding it....
And this option seems to be alot quicker I would of thought...
Now I think the second option would be the best, but I am pretty sure it can be done without using the amount of code wordpress use.
Is there a way of changing the url of an image when adding it as NSTextAttachment? Because when you convert NSAttributedText to html, the image just gets the local link to the file, and the name of the file is just "attachment"..
Now If anyone could give me some advice or better options that would be great!
Many thanks to anyone that spares some time to read this!
Create an image upload service which accept image and url as argument. Then you can generate those image url before sending them to image server and replace those local url with the generated image url.
Edit:
Maybe you can store the location of those images and remove them from the NSattributedstring first and replace with <img src = "url"> before converting it to "HTML".
But I would suggest you using one of those HTML Parser such as KANNA.

How to display image which is stored on s3 without storing on harddisk?

In my rails app I have used attachment_fu to upload images and stored it on s3.
I want to display these images on browser without retrieving it.
How can I display images by giving s3 path?
Thanks,
Jayashri
You just need to link to the correct S3 path for you images.
For public files they are in the format:
eg http://s3.amazonaws.com/[bucket]/[key]
If your content is private you'll need to create a signed url but all the SDKs and libraries make this easy.
Then use the url to display the images:
<img src="http://s3.amazonaws.com/mybucket/myfile.jpg" ... ></img>
It may help you to install the S3 organizer in Firefox so you can browser your directories. Then I believe the URL's are structured kinda like this...
http://BUCKET.s3.amazonaws.com/FOO/BAR.png

Resources