public
Description: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
Homepage: http://weblog.techno-weenie.net
Clone URL: git://github.com/technoweenie/attachment_fu.git
Click here to lend your support to: attachment_fu and make a donation at www.pledgie.com !
Modified README to include information about 'uploading' files from a 
script
eadz (author)
Sun Jun 08 21:58:30 -0700 2008
commit  dfc4ada55dd0f982a6fc2fbaa297e58070096105
tree    e08b12b1b849db79c3eb8da401cefbcc373d180d
parent  1e46a77ef23fdaa8e57754a087d7a5e163bd9f99
0
...
173
174
175
176
177
178
179
 
180
181
 
 
182
183
 
184
 
 
 
...
173
174
175
 
 
 
 
176
177
 
178
179
180
 
181
182
183
184
185
0
@@ -173,12 +173,13 @@ The following example shows how to upload a file from a script.
0
 require 'action_controller'
0
 require 'action_controller/test_process.rb'
0
 
0
-@attachable = AttachmentMetadataModel.new(:uploaded_data => ActionController::TestUploadedFile.new(path, mimetype))
0
-@attachable.save
0
-
0
-This will "upload" the file at path and create the new model.
0
+path = "./public/images/x.jpg"
0
 
0
-mimetype is a string like "image/jpeg". One way to get the mimetype for a given file on a UNIX system
0
+# mimetype is a string like "image/jpeg". One way to get the mimetype for a given file on a UNIX system
0
+# mimetype = `file -ib #{path}`.gsub(/\n/,"")
0
 
0
-mimetype = `file -ib #{path}`.gsub(/\n/,"")
0
+mimetype = "image/jpeg"
0
 
0
+# This will "upload" the file at path and create the new model.
0
+@attachable = AttachmentMetadataModel.new(:uploaded_data => ActionController::TestUploadedFile.new(path, mimetype))
0
+@attachable.save

Comments

    No one has commented yet.