やりたいこと
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'
で出来た!