# 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:** 1

<div class="post-metadata">

**Author:** ![Saurabh\_Khandelwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saurabh_khandelwal/32/156332_2.png) [@Saurabh\_Khandelwal](https://meta.discourse.org/u/Saurabh_Khandelwal)\
**Post date:** [2020 年 4 月 22 日午後 3:23 UTC](https://meta.discourse.org/t/how-to-upload-image-using-discourse-api/148869/1 "2020-04-22T15:23:55Z")

</div>

こんにちは、皆様。

Java コードから以下の Discourse API を使用して画像をアップロードしようとしています：  
[https://discourse.example.com/uploads.json](https://discourse.example.com/uploads.json)

Body に以下の JSON を渡しています：  
{  
“type” : “avatar”,  
“user\_id”: 1,  
“synchronous”: true,  
“file”: “Binary String”  
}

しかし、レスポンスでは以下の結果が返ってきます：

{  
“failed”: “FAILED”,  
“message”: “undefined method `tempfile’ for #String:0x000055fc2e0a01d8”  
}

どこが間違っているのでしょうか？  
ご協力をお願いします。

---

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