-
Notifications
You must be signed in to change notification settings - Fork 53
SavingImages
Squeegy edited this page Sep 12, 2010
·
2 revisions
These assignment methods can be used in two ways. First they can be called directly.
my_photo.image_file = File.new('path/to/file.png', 'rb')
Or they can be called via mass assignment.
Photo.new(:image_file => File.new('path/to/file.png', 'rb')
Photo.new(params[:photo]) #where params[:image_file] is an uploaded image
This is the most common assignment method. This will work with an instance of any IO
object, such as File
or StringIO
. it will also work with file upload fields in your forms.
Fetches an image from a url
on the internet and saves it with the record.
Reads the image from a string of file data. This can be used with the result of something like File.read('my_image.jpg', 'rb')
.
Reads the image from a string of base64 encoded file data.
This one is used internally to make forms redisplay safe. It expects the named of a file in your apps tmp
directory. You probably shouldn’t need to use this one.