Skip to content

Instantly share code, notes, and snippets.

@liluo
Created November 30, 2012 15:02
Show Gist options
  • Save liluo/4176272 to your computer and use it in GitHub Desktop.
Save liluo/4176272 to your computer and use it in GitHub Desktop.
Douban API v2 上传图片 length mismatch
class Faraday::Parts::FilePart
def initialize(boundary, name, io)
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
io.respond_to?(:opts) ? io.opts : {})
@length = @head.length + file_length
@io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new("\r\n"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment