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 !
added docs on how to script an uploaded file
eadz (author)
Sun Jun 08 21:46:19 -0700 2008
commit  b6211f21c13ef655b7e2f60bdbd8b42f9c35bd46
tree    919c16df2a6922b32da455a72f4093b5d7580112
parent  d433f786c8a9c28de82ae416bab66261666b1c68
0
...
160
161
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
0
@@ -160,3 +160,25 @@ Example in controller:
0
       render :action => :new
0
     end
0
   end
0
+
0
+attachement_fu scripting
0
+====================================
0
+
0
+You may wish to import a large number of images or attachments.
0
+The following example shows how to upload a file from a script.
0
+
0
+#!/usr/bin/env ./script/runner
0
+
0
+# required to use ActionController::TestUploadedFile
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
+
0
+mimetype is a string like "image/jpeg". One way to get the mimetype for a given file on a UNIX system
0
+
0
+mimetype = `file -ib #{path}`.gsub(/\n/,"")
0
+

Comments

    No one has commented yet.