class Fog::Proxmox::MultipartIsoUpload
Prepares a streamed multipart ISO upload and its content type.
Attributes
body[R]
content_type[R]
Public Class Methods
new(body_params)
click to toggle source
# File lib/fog/proxmox/compute/models/multipart_iso_upload.rb, line 28 def initialize(body_params) filename = body_params.fetch(:filename) raise ArgumentError, "Invalid ISO filename: #{filename}" unless filename.match?(/\A[a-zA-Z0-9][a-zA-Z0-9._-]*\.iso\z/i) file = body_params.fetch(:file) boundary = '-' * 30 + SecureRandom.hex(15) prefix = build_multipart_content(boundary, 'content', 'iso') prefix << build_multipart_header(boundary, 'filename', filename: filename) @body = MultipartBody.new(prefix, file, build_multipart_closing(boundary)) @content_type = "multipart/form-data; boundary=#{boundary}" end
Private Instance Methods
build_multipart_closing(boundary)
click to toggle source
# File lib/fog/proxmox/compute/models/multipart_iso_upload.rb, line 59 def build_multipart_closing(boundary) "#{Excon::CR_NL}--#{boundary}--#{Excon::CR_NL}".b end
build_multipart_content(boundary, name, value)
click to toggle source
# File lib/fog/proxmox/compute/models/multipart_iso_upload.rb, line 55 def build_multipart_content(boundary, name, value) build_multipart_header(boundary, name) << value << Excon::CR_NL end
build_multipart_header(boundary, name, filename: nil)
click to toggle source
# File lib/fog/proxmox/compute/models/multipart_iso_upload.rb, line 44 def build_multipart_header(boundary, name, filename: nil) newline = Excon::CR_NL header = ::String.new(encoding: Encoding::BINARY) header << "--#{boundary}#{newline}" header << %(Content-Disposition: form-data; name="#{name}") header << %(; filename="#{filename}") if filename header << newline header << "Content-Type: application/octet-stream#{newline}" if filename header << newline end