5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HipChat APIでファイルを送ろうとしてはまった

Last updated at Posted at 2014-12-18

やりたいこと

HipChatのルームにスクリプトでファイルを送りたい

やってみた

curlでローカルのファイルを送ってみた。

curl https://api.hipchat.com/v2/room/${ROOM_ID}/share/file?auth_token=${API_TOKEN} -X POST -H "content-type=multipart/related" -F 'file=@sample.jpg;type=image/jpeg'

できない。。。

エラーが返ってくる。

{
	"error": {
	"code": 400,
	"message": "Request must be sent using UTF-8",
	"type": "Bad Request"
}

なぜか文字コードを怒られる。。。

 
切り分けのためにテキストファイルを送ってみる。

curl ttps://api.hipchat.com/v2/room/${ROOM_ID}/share/file?auth_token=${API_TOKEN} -X POST -H "content-type=multipart/related" -F 'file=@hoge.txt;type=text/plain'

 

{
	"error": {
	"code": 400,
	"message": "The request requires a properly encoded body with the 'content-type' header set to '['multipart/related']",
	"type": "Bad Request"
}

お、エラーが変わった。
でもcontent-typeはmultipart/relatedで指定してるはず。。。
 
試しにcurlに--trace-asciiオプションをつけて中身を見てみる。

〜
00d5: Content-type:multipart/form-data;
〜

あれ。。。

出来た

結局、書き方が違ってただけという。
× "content-type=multipart/related"
○ "Content-type:multipart/related"

curl https://api.hipchat.com/v2/room/${ROOM_ID}/share/file?auth_token=${API_TOKEN} -X POST -H "Content-type:multipart/related" -F 'file=@sample.jpg;type=image/jpeg'

で出来た!

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?