summaryrefslogtreecommitdiffstats
path: root/lib/redmine/utils.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/redmine/utils.rb')
-rw-r--r--lib/redmine/utils.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/redmine/utils.rb b/lib/redmine/utils.rb
index 56350052f..ed27d7e84 100644
--- a/lib/redmine/utils.rb
+++ b/lib/redmine/utils.rb
@@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+require 'fileutils'
+
module Redmine
module Utils
class << self
@@ -40,6 +42,25 @@ module Redmine
def random_hex(n)
SecureRandom.hex(n)
end
+
+ def save_upload(upload, path)
+ directory = File.dirname(path)
+ unless File.exists?(directory)
+ FileUtils.mkdir_p directory
+ end
+ File.open(path, "wb") do |f|
+ if upload.respond_to?(:read)
+ buffer = ""
+ while (buffer = upload.read(8192))
+ f.write(buffer)
+ yield buffer if block_given?
+ end
+ else
+ f.write(upload)
+ yield upload if block_given?
+ end
+ end
+ end
end
module Shell