Skip to content

Commit

Permalink
added docs on how to script an uploaded file
Browse files Browse the repository at this point in the history
  • Loading branch information
eadz committed Jun 9, 2008
1 parent d433f78 commit b6211f2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,25 @@ Example in controller:
render :action => :new
end
end

attachement_fu scripting
====================================

You may wish to import a large number of images or attachments.
The following example shows how to upload a file from a script.

#!/usr/bin/env ./script/runner

# required to use ActionController::TestUploadedFile
require 'action_controller'
require 'action_controller/test_process.rb'

@attachable = AttachmentMetadataModel.new(:uploaded_data => ActionController::TestUploadedFile.new(path, mimetype))
@attachable.save

This will "upload" the file at path and create the new model.

mimetype is a string like "image/jpeg". One way to get the mimetype for a given file on a UNIX system

mimetype = `file -ib #{path}`.gsub(/\n/,"")

0 comments on commit b6211f2

Please sign in to comment.