SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Miami, FL
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to save images to a subdirectory

    Hi everyone,

    OK, so I've got an app together, deployed on a Joyent Accelerator, and realized that whenever I redeploy changes I've made, subversion goes ahead and gets rid of everything in the images/users directory (images uploaded by users are thrown in there within trees and trees of categorical directories.) That's understandable, I expect that to happen now that I think about it.

    What I would like to do now is save those images in a subdirectory or something which is not associated with the app, for instance, http://images.myserver.com.

    Right now, I'm writing the file as such:

    Code Ruby:
    @dir = "#{RAILS_ROOT}/public/images/users/#{@substring_dir}/#{@user.screen_name}/#{@classified.id}"
    File.makedirs @dir

    Then the file is saved in that new directory, which would be something like this: "http://myserver.com/images/users/u/s/e/user1/coolimage.jpg"

    I would like it to be: "http://images.myserver.com/users/u/s/e/user1/coolimage.jpg"

    I'm assuming the subdirectory won't be associated with the app, so I can update the app with subversion to my heart's content and those files in the image subdirectory won't be affected. Not like I know how to even create subdirectories yet, but I suppose that's something for another forum

    Thanks in advance!

  2. #2
    l 0 l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I was trying to remember how I dealt with it since I went through the exact the same process as you a year ago- at least that's a good sign of when you figure it out you don't have to deal with it again for years.

    Anyway, after a few unsuccessful tries (like using Rails to send the binary bits of each image using send_file, which was a terrible idea) I ended up using a symbolic link. That meant I could toss my images somewhere outside of my Subversion repository that didn't get overwritten every time I checked a new version in, and since it's a symbolic link to a folder in my /images folder I didn't have to deal with trying to figure out how to link to images- they were just there, thanks to the magical powers of symbolic links.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Miami, FL
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I realized I meant to say subdomain, but you understood nonetheless.

    That solution looks like the way to go. What I was thinking of doing was instead of saving at "#{RAILS_ROOT}/public/images/...", I would save directly under the directory where I was pointing my subdomain to, something like "/var/www/subdomains/images/..."

    I'd have to go back and change a bit of code to make sure all user-uploaded images read from there, but I figured it would work. Your idea looks much simpler :-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •