# Discourse API を使用して画像をアップロードする方法

**URL:** <https://meta.discourse.org/t/how-to-upload-image-using-discourse-api/148869>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [2020 年 4 月 22 日午後 3:23 UTC](https://meta.discourse.org/t/how-to-upload-image-using-discourse-api/148869 "2020-04-22T15:23:55Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![dhanya](https://avatars.discourse-cdn.com/v4/letter/d/d26b3c/32.png) [@dhanya](https://meta.discourse.org/u/dhanya)\
**Post date:** [2020 年 9 月 22 日午後 4:36 UTC](https://meta.discourse.org/t/how-to-upload-image-using-discourse-api/148869/4 "2020-09-22T16:36:32Z")

</div>

これが私のサンプルデータです  
Array  
(  
[type] =\> avatar  
[user\_id] =\> 3  
[synchronous] =\> 1  
[file] =\> 1101000 1110100 1110100 1110000 1110011 111010 101111 101111 1101011 1101001 1111000 101101 1100100 1100101 1110110 101110 1100001 1110011 1110011 1111001 1110011 1110100 101101 1110101 1100011 101110 1100011 1101111 1101101 101111 1110011 1101001 1110100 1100101 1110011 101111 1100100 1100101 1100110 1100001 1110101 1101100 1110100 101111 1100110 1101001 1101100 1100101 1110011 101111 1110000 1101001 1100011 1110100 1110101 1110010 1100101 1110011 101111 110010 110000 110010 110000 101101 110000 110111 101111 1101011 1101001 1111000 1110100 1100101 1100001 1101101 1011111 1101001 1101101 1100111 110001 101110 1101010 1110000 1100111  
)

バイナリ文字列としてファイルを送信しています。以下のようにレスポンスが返ってきます。これは Drupal です。

`/uploads.json` が `422 Unprocessable Entity` レスポンスを返しました: {“failed”:“FAILED”,“message”:“undefined method `tempfile’ for #\u003cArray:0x00007f0d5c784810\u003e”}

Drupal と Discourse の統合を試みています。

---

_[View the full topic](https://meta.discourse.org/t/how-to-upload-image-using-discourse-api/148869)._
