I'm using Paperclip-FFMEG to upload video files to my development environment (and, eventually, to a local server when my project goes into production).
When videos are uploaded, the filename is, by default, as follows:
/system/modelnames/paperclipnames/.../mynewfile.mp4?xxxxxxxxxx
I believe the 10 digit figure after the questionmark is a timestamp.
However, the player I will be using to play the videos doesn't like to have anything after the file attachment - so I would like to strip the questionmark, and the timestamp after it, before passing the URL into the player.
I tried to use the following Ruby (I think) strip function:
temp_variable = model.paperclipattribute.url(:blah).strip('?')[0]
However, Rails throws up an error:
wrong number of arguments(1 for 0)
I take it I'm doing this wrong? Any other solutions? I don't want to switch off timestamps entirely, as I only need to do so in this situation.
Thanks!
If you want to do this everywhere for a given attachment and without the need to pass the extra parameter, you can set the use_timestamp
option when calling the has_attached_file
method in your model. So, to build on the example given in the Paperclip README:
has_attached_file :avatar,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "/images/:style/missing.png",
:use_timestamp => false
Hope this is OK to put as an answer to my own question (as it may be useful for others who stumble across this post), but I've since discovered that an alternative (and more appropriate) way to deal with this issue is to add the false
parameter to URL() as follows when displaying the content in your view:
model.paperclipattribute.url(:whateverstyle, false)
The timestamp will automatically be removed. I think this is better, as the split
method I suggested might remove content you don't intend to remove - for example, if your file is called something like "Is_this_a_question_?_Yes_it_is.mp4?xxxxxx", then everything after the first question mark might be removed (i.e. the file will be read as "Is this a question_", thus corrupting the filename.
I haven't tested this, so I may be wrong.
Globally default them to off, just put this in a config/initializers/paperclip.rb file.
Paperclip::Attachment.default_options[:use_timestamp] = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With