Active Storage: filenames with special characters - ruby-on-rails

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.

Related

Transloadit Thumbnail Result Image Has Wrong File Extension Capitalization

I am using transloadit to generate a thumbnail image sent from an iOS app that saves both the original image and the thumbnail to Amazon S3. The files get get saved out correctly with one exception. The file name for the thumbnail does not retain the capitalization of the original filename for the file extension, i.e. JPG vs jpg. Here is my template:
I am using the fields to generate the custom path I want--which works fine, however, the output from the "store_thumb" step has this difference:
Is there any way to retain the capitalization? I realize I can just force all of my filenames from the app to lowercase, however, I thought maybe I am just doing something wrong. Any suggestions?
I'm part of Transloadit's developer support team.
First of all, let me assure you there's nothing wrong with what you're doing. Secondly, I've asked our engineers about the issue and we realized it's a limitation caused by our special usage of some of the conversion tools.
We'll do our best to address this on future versions, but we cannot commit on a date. So for now if it's causing you trouble, we recommend using lowercase letters.

iOS file upload - original filename

I have a simple HTML file upload snippet that works under iOS as well. However my problem is that the filename of the uploaded file will always be 'image.jpeg'. Is there a way to get the original filename - i.e. 'IMG_0001.jpg' instead? The major issue is that if I have 2 files selected they both have the name of 'image.jpeg' as opposed to their unique names.
Safari on iOS will always make the name of the uploaded file image.jpeg, presumably for security/privacy purposes. You need to generate your own name for the files, which is a good idea in general for uploaded files: you never want to trust the client too much.
If you are targeting more than just Safari on iOS, you will still need to handle this case because it is reasonable that people might upload multiple files with the same name, but originally located in different directories.

Images tags not showing in wicked_pdf gem

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

Imagemagick integrated with Meteor

I am attempting to use Imagemagick to manipulate images that are uploaded by a user. Right now I have a simple set of Imagemagick.convert[ ] commands server side that preform a variety of tasks on the uploaded image. My problem comes from Imagemagick needing the file data to be read into meteor and not from a url. What I end up doing is writing the uploaded file to the /public folder where Imagemagick is able to manipulate the image. However because the list of Imagemagick.convert commands (saving and writing to /public), the application keeps refreshing, breaking up the processes and sending it into an infinite refreshing cycle. I don't think assets is a viable solution, but I need some folder that I can write to in meteor that will not interrupt the various Imagemagick processes through a refresh. I have tried the .folder for a hidden folder, but meteor gives me an error: "You can’t use a name that begins with a dot “.”, because these names are reserved for the system. Please choose another name." Any thoughts?
#Nate I wrote a little example app that solves this problem by using a temporary directory (as others have suggested):
https://github.com/ideaq/image-uploads
My solution gives you:
Easy image uploading in any Meteor app
Images are re-sized to Thumbnail, Mobile Optimised and Full-size Original
Images are uploaded to AWS S3 for CDN delivery (scalability and speed)
A thumbnail of the image is displayed on to the user without refreshing the page
if you found a better way of doing image uploads in meteor, please share! thanks. :-)

How to show only the link of an uploaded file, not its location

I have used paperclip to allow me to upload files to a rails application. Everything works and the file is uploaded, but instead of seeing a link to the actual file itself I see the location of it within the systems folder of the rails project.
I'm guessing its either a routing issue or I need to create a link to the file in question. However, I would like to hide the location of the file itself, and only see the link displayed.
I would be very grateful if someone could point me in the right direction here.
You want to hide the actual path of the file in the server, right?
You can achieve that using send_file (http://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_file) in a normal controller.
You will still need to do something to protect the download using the real path.

Resources