OK, so, this is a *HUGE* method in a controller.

1. Extract lines 25~48 to a method
2. Put that method on a class that is instantiated with just the data you need (say, the file upload location,the params[:node][:content] and the params[:story][:upload])
3. Add some tests
4. Genericize and extract lines 41~47 into a method.

The way this looks right now, I would *NOT* merge this pull request into a master that I have any responsibility for regularly delivering software on.