Attaching files through attachment_fu

Hi

I wish to upload a file not from the view but from the controller itself. I have the file's path and mimetype and size. I would like to know How it can be done directly from the controller

Thanks in Advance

Charanya Nagarajan wrote:

Hi

I wish to upload a file not from the view but from the controller itself. I have the file's path and mimetype and size. I would like to know How it can be done directly from the controller

Thanks in Advance

filepath = File.open("File_path","r") File.open(path_where_u_want_to_upload, "wb") { |f| f.write(filepath.read) }

I always prefer to actually generate an uploader object just as it would come from the view itself.

Mock method to simulate an actual uploaded file

def mock_uploader(path, type = ‘application/octet-stream’)

uploader = ActionController::UploadedStringIO.new

uploader.original_path = path

uploader.content_type = type

def uploader.read

File.read(original_path)

end

def uploader.size

File.stat(original_path).size

end

uploader

end

Best regards

Peter De Berdt