Sha256: 1d699765d3a5e3613bf4d299ba8ce8deab4ee638d6c2c1f770afe95d9ddefcb4

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

# = RequestPart
#
# Encapsulates a multipart part.
#
# code:
# George Moschovitis  <gm@navel.gr>
#
# (c) 2004 Navel, all rights reserved.
# $Id: request-part.rb 71 2004-10-18 10:50:22Z gmosx $

require "cgi"
require "ftools"

require "n/utils/string"
require "n/utils/uri"
require "n/utils/http"
require "n/app/cookie"

module N; module App

# RequestPart
#
# This class encapsulates a part in a multipart request.
# A part is typically an uploaded files.
#
class RequestPart
	# the filename of the part
	attr_accessor :filename

	# the original filename path
	attr_accessor :original_path

	# the temp filename path
	attr_accessor :body

	# the content-type
	attr_accessor :content_type

	def initialize(original_path, body, content_type = nil)
		@original_path = original_path
		@body = body
		@content_type = content_type
		# handle dos + unix separators.
		@filename = @original_path.split(/\/|\\/).last
	end
	
	# gmosx: 
	# Hack fixed save for webrick!
	#
	def save(prefix, forced_filename = nil, forced_extension = nil)
		# ARGH!! local path is used for something else, FIXME!!
		::FileUtils.mkdir_p(prefix)
		save_path = "#{prefix}/#{@filename}"
		::File.open(save_path, "wb") {|f| f.write @body }
		return save_path
	end	
end

end; end # module

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.1.2 lib/n/app/request-part.rb