Topic: [attachment_fu] Weird storage path

Hi everyone,
Until now i was using acts_as_attachment plugin and it was working fine. But I wanted to switch to attachment_fu instead. at first sight everything seems to work but i get a weird storage path, for example:

my uploaded_file with id=18 is stored in : /public/uploaded_file/0000/0018

Why do i get this "/0000/00" ?
How to get rid of it ?

My uploaded_file.rb looks like this :

class UploadedFile < ActiveRecord::Base
  belongs_to :project
 
  acts_as_attachment :storage => :file_system
  validates_as_attachment
end

Re: [attachment_fu] Weird storage path

Think you can specify the path

path_prefix => 'somepath'

theres a tut here

--

Re: [attachment_fu] Weird storage path

Yes I tried that too, but it do not change anything...

:path_prefix => "/public/uploaded_files"

Re: [attachment_fu] Weird storage path

Try putting this in your UploadedFile model:

def partitioned_path(*args)
   ["%04d" % attachment_path_id] + args
end

Alex

Re: [attachment_fu] Weird storage path

Oh yes, great! It works fine. Thanks a lot

So what was the problem actually ?

How is the default partitioned_path created?

Re: [attachment_fu] Weird storage path

Well it wasn't actually a problem; more of a design decision. Many servers will run into problems if a lot of files or folders are stored in one directory (usually about 32,000). The easiest way to get around this issue is to split the directories into two layers: so id 2 is stored in 0000/0002, id 54321 goes in 0005/4321 and so on.

While this does make things more scaleable, it can be overkill if you're not expecting many uploads.

Anyway, this was the original code:

def partitioned_path(*args)
    ("%08d" % attachment_path_id).scan(/..../) + args
end

The bit in brackets takes the attachment id and pads it with up to 8 0s (so 123 becomes 00000123). The scan(/..../) splits the new, longer number into to groups of 4 and puts them into an array. Any additional arguments are then added on.

The overwriting code is in essence the same, except it only pads the id up to 4 digits, and doesn't split it into two directories. Oh and I forgot to mention, if you didn't want the number to be padded up at all, you could do:

[attachment_path_id.to_s] + args

instead.

Hope this makes sense wink

Alex

Re: [attachment_fu] Weird storage path

Alex,
I wish I noticed your post when I had the same question.  Would have saved me a lot of time.

cheers