filename..extension // Paperclip reprocess - ruby-on-rails

Some kind of problem I can't resolveā€¦
In some app, a method called on :before_create was prefixing the file's extension with a double-dot (ex. /images/13402/medium/hey-1..jpg)
The problem is fixed for the new ones, but nothing occurs when I apply a reprocess! on the old ones; and I'd like to know if anyone could help about it

Reprocess / refresh only takes your original image and recreates the defined styles in your model class. So if your original image contains a file path with double dots in it, these are also applied to the generated styles. You have to clean up your original files and the stored file paths in your model records.
The only way I know would be to write a little script to modify this. Basically
foreach image
strip out double dots from original file name
rename file
store new file path in model record
end
And then rake paperclip:refresh

Related

How to replace an entire file using FileManager

Let's say I have an UIImage cached in my Cache folder:
/.../Cache/Image Cache/<firstImage.id>
Now I want this folder to only ever have 10 image cached at a time, so if a new one comes in I want to take a file and replace the entire file and not just the contents of it. I.e.
/.../Cache/Image Cache/<firstImage.id> becomes
/.../Cache/Image Cache/<secondImage.id>.
As far as I can tell, replaceItem(at:withItemAt:backupItemName:options: only replaces the contents of the file but the file name remains the same. And I'm not too sure what replaceItem(at:withItemAt:backupItemName:options:resultingItemURL:) does even though it might be what I'm looking for (I don't know what an AutoreleasingUnsafeMutablePointer<NSURL?>? was but it sounded dangerous so I decided to leave it alone, specially since it has the word "unsafe" in it).
Is there a straightforward way of doing using an in-built function or is manually deleting the old file and adding the new file the best way? Please let me know.
Thanks in advance!

How to create Trailer Record in Flat File using SSIS

I am looking for some help on how to create a trailer record in a flat file using SSIS, I have create a SSIS package that creates a custom header and loads other record from the database into the flat file, it is a fixed width flat file. Now at the end of the file I want to create a Trailer Record along with some static text and Record count. I tried looking on to google but could not get any good example. Any help is much appreciated.
Use a Script Task. Take the file path of the fixed width flat file that you have obtained as a input variable. Once withing the script task use the .Net coding to append the data that you need. I have written a post on it - https://karbimantras.wordpress.com/2016/08/12/adding-record-count-to-flat-file/

update database with a ruby function

I have a series of folders that all have files I need linked to the database (via there file path). One option I could do is manually insert all the file paths into my database, however, this can be painful as the number of folders will keep increasing and manual uploading will take too much time.
Is there a way to write a ruby helper function that will search these folders and automatically add the path to the files into a column in my database?
All the file paths have a recognizable pattern, for example:
Tel/a_1/poi1/names.csv
Tel/a_2/poi1/names.csv
Tel/a_3/poi1/names.csv
I need a function that will occupy a field in my database with the path of each of these names.csv files. Very new to ruby and rails, so any help is greatly appreciated. Also, please let me know if anything is unclear.
Something like this should give u all the filenames in the folder, for you to manipulate:
Dir["Tel/**/**/*.csv].each do |file|
* update attribute of your model with the path of the file
end
Read about the Dir object too.
Thats a example to get all files.
Dir["Tel/a_*/poi1/names.csv"] return a Array with path about all files.

Check condition if image available in upload folder or not, in rails3?

I'm using carrier wave to upload images in rails3,
i want to just check the condition is image available in upload folder or not.
Because in my case suppose image name available in data base but by mistake image deleted from upload folder in that scenario when click on image link getting error .
I think, this can be done using exist?(file_name) method of Ruby File Class. I assume you can get the full path of the file from the database, and pass it to the class method as follows:
File.exist?('full/path/of/the/file')
This will return true if the file exists otherwise false. for reference you can read about File operations here
Carrierwave has a built-in method to do just that. It works whether your storage method is :file or :fog. Looks like this:
picture.data.file.exists?

How can I make Paperclip's attachment path value immutable?

The Rails plug-in Paperclip interpolates the attachment path based on some dynamic user-defined rules each time the path is requested. This allows you to put names/IDs/etc. into the paths of your attachments.
However, I have two cases where the original path dependencies can change, and when they do I can no longer find the attachment anymore, because the interpolated path now points to the wrong place.
I need the path to be interpolated just once, when the file is saved, then that path preserved and returned there after regardless of the interpolation dependencies changing.
a colleague of mine came up with a good solution. it's not seamlessly integrated into paperclip but it's effective. the gist is:
using a "before_create" filter on the model to take a snapshot of all the values used in the path that could change
referencing those snapshotted values from the paperclip path interpolation (as opposed to the actual source, which could change)
so your path definition looks something like this:
:path => '.../:snapshotted_name/...'
and the code looks something like this:
before_create :snapshot_names # only set once
private
def snapshot_names
snapshotted_name = customer.name
end
I found the problem.
I have two cases where the original path dependencies can change
Why will they change? What are these two cases? What is preventing you from coming up with a scheme whereby they will never change?

Resources