Method: ChatWork::Client::FileMethods#create_file

Defined in:
lib/chatwork/client/file_methods.rb

#create_file(room_id:, file:, message: nil) {|response_body, response_header| ... } ⇒ Hashie::Mash Also known as: upload_file

Upload a new file to room

Examples:

how to upload a file

client = ChatWork::Client.new(api_key: "XXX")
client.create_file(room_id: 11111111, file: Faraday::UploadIO.new("/path/to/file.txt", "text/plain"), message: "Test")

response format

{
  "file_id": 1234
}

Parameters:

  • room_id (Integer)
  • file (Faraday::UploadIO)
  • message (String) (defaults to: nil)

Yields:

  • (response_body, response_header)

    if block was given, return response body and response header through block arguments

Yield Parameters:

  • response_body (Hashie::Mash)

    response body

  • response_header (Hash<String, String>)

    response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Returns:

  • (Hashie::Mash)

See Also:



92
93
94
95
96
97
98
99
# File 'lib/chatwork/client/file_methods.rb', line 92

def create_file(room_id:, file:, message: nil, &block)
  params = {
    file:    file,
    message: message,
  }

  post("/rooms/#{room_id}/files", params, &block)
end