HTTP::FormData::Parser

class HTTP::FormData::Parser

Defined in:

http/formdata/parser.cr

Class Method Summary

  • .new(io, boundary)

    Create a new parser which parses io with multipart boundary boundary.

Instance Method Summary

Class Method Detail

def self.new(io, boundary)Source

Create a new parser which parses io with multipart boundary boundary.

Instance Method Detail

def has_next?Source

True if #next can be called legally.

def next(&block)Source

Parses the next form-data part and yields field name, io, FileMetadata, and raw headers.

This method yields once instead of returning the values, because the IO object yielded to the block is only valid while the block is executing. The IO object will be closed as soon as the block returns. To store the content of the body part for longer than the block, the IO must be read into memory.

form_data = "--aA40\r\nContent-Disposition: form-data; name=\"field1\"; filename=\"foo.txt\"; size=13\r\nContent-Type: text/plain\r\n\r\nfield data\r\n--aA40--"
parser = HTTP::FormData::Parser.new(IO::Memory.new(form_data), "aA40")
parser.next do |part|
  part.name                    # => "field1"
  part.io.gets_to_end          # => "field data"
  part.filename                # => "foo.txt"
  part.size                    # => 13
  part.headers["Content-Type"] # => "text/plain"
end

© 2012–2017 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.22.0/HTTP/FormData/Parser.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部