Class: DistributedPress::Multipart

Inherits:
Object
  • Object
show all
Defined in:
lib/distributed_press/multipart.rb

Overview

Deals with multipart requests

Constant Summary collapse

NEWLINE =

Newlines

"\r\n"
BOUNDARY =

Boundary separator

'--'

Instance Method Summary collapse

Instance Method Details

#boundaryString

Generate a MultiPart boundary and reuse it

Returns:

  • (String)


47
48
49
# File 'lib/distributed_press/multipart.rb', line 47

def boundary
  @boundary ||= HTTParty::Request::MultipartBoundary.generate
end

Write the multipart footer

Parameters:

  • io (IO)


34
35
36
37
38
39
40
41
42
# File 'lib/distributed_press/multipart.rb', line 34

def write_footer(io)
  io.write NEWLINE
  io.write BOUNDARY
  io.write boundary
  io.write BOUNDARY
  io.write NEWLINE

  nil
end

#write_header(io, filename) ⇒ Object

Write the multipart header

Parameters:

  • io (IO)
  • filename (String)


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/distributed_press/multipart.rb', line 18

def write_header(io, filename)
  io.write BOUNDARY
  io.write boundary
  io.write NEWLINE
  io.write "Content-Disposition: form-data; name=\"file\"; filename=\"#{filename}\""
  io.write NEWLINE
  io.write 'Content-Type: application/octet-stream'
  io.write NEWLINE
  io.write NEWLINE

  nil
end