Hey Guys,
I need to build an image upload and resize script.
I tried file_column, but you can’t rename the uploaded files with it and
every time I try to output an image i get…
Can you see the numbers at the end of the file name? I have no idea
where they come from!
So, I’ve been trying to adapt this script for my needs…
http://railsforum.com/viewtopic.php?id=962
It does pretty much what I need it to do, and it works just fine if I
have a model called ‘product’. When I try and use it on a model called
‘photo’ I just can’t get it to work. I went through the script and every
time it mentioned ‘product’ i just replaced it with ‘photo’. Is there
anything else I would have to do?
Here is what I’m trying to do…
- Upload image to file system
- Rename image to a unique filename
- Resize image to 3 different sizes
- Create a folder (if it does not exist). Folder name =
session[:user_id]
- Store images in the correct users folder
- Store the file names into the ‘photos’ table
- Store the current users id (taken from session[:user_id]) into the
‘photos’ table in the ‘user_id’ column
This must be a pretty common task, yet I can’t seem to be able to find
any information on it and it’s driving me slightly crazy!
Any help would be very much appreciated.
Scott
I like file_column… I use it all the time… but what would you rename
the
files to?
The numbers on the end of the filenameare there because Rails puts them
there. Those numbers help ensure that your browser doesn’t cache the
image.
The numbers are based off of the last modified date of the image… so
it
will cache until the image changes on disk.
Brian H. wrote:
I like file_column… I use it all the time… but what would you rename
the
files to?
The numbers on the end of the filenameare there because Rails puts them
there. Those numbers help ensure that your browser doesn’t cache the
image.
The numbers are based off of the last modified date of the image… so
it
will cache until the image changes on disk.
Ahh! Thanks for the explanation with regards to the numbers at the end
of the filename.
I want to store images in folders which are named after the user id of
the user uploading photos. It just seems more logical than creating a
new folder for every single image.
I see where you’re going… but my advice would be to leave it an move
on.
It may not be the URL you want, but is that really necessary? I’d take
the
tradeoff instead of reinventing the wheel.
In a few weeks if you really want to change it you could actually change
where file_column stores the images… you could then make your own
method
that uses send_data. That’s how you’d do secure downloads, for example.
you could also look into file_column a bit, you’ll see where the naming
takes place. It could be a neat little excercise for you to add an
option
that modifies where the record is saved. With some Ruby-fu, it could be
simple.
Best of luck!