Capistrano and Uploaded Documents

I have an application I'm working on which allows me to upload files. The files are stored somewhere in the public directory so that they can be accessed directly. When I deploy an update with Capistrano, I 'lose' the files because of the current symlink points to the new checked out version.

Before I start working on a solution, has anyone else already solved this problem?

Stephen Gerstacker

Stephen,

If you store your uploaded files in public/system they won’t get overwritten with every code update.

Hammed

Yup.

put them in the shared dir, or any other dir outside of those releases dir. You can do this to your app like so:

create a directory in the deploy_to/shared dir, let's call it file_storage. Copy all your current files to this /shared/file_storage dir. now, remove the dir and create a symlink to it.

Now, to make sure that dir gets symlinked everytime during a depoy, create a task called after_update_code. In it, symlink the dir, like so:

desc "Tasks to execute after code update" task :after_update_code, :roles => [:app, :db] do # uploaded file record storage run "rm -Rf #{release_path}/file_storage" run "ln -s #{uploaded_files_path}/file_storage #{release_path}/file_storage" end

The rm removes the symlink and the ln -s relinks it back.

in this case, uploaded_files_path could be: deploy_to/shared/files or just a dir /upload on your server root.

hope this helps. cheers!

Thanks, that worked like a charm.

Stephen Gerstacker