# API 게시글에 이미지 추가하기

**URL:** https://meta.discourse.org/t/add-images-to-api-posts/204651
**Category:** Development
**Tags:** rest-api
**Created:** [9월 28, 2021, 2:07오후 UTC](https://meta.discourse.org/t/add-images-to-api-posts/204651 "2021-09-28T14:07:43Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![mapengfei-nwpu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mapengfei-nwpu/32/203450_2.png) [@mapengfei-nwpu](https://meta.discourse.org/u/mapengfei-nwpu)
#### Post date: [1월 14, 2022, 6:44오후 UTC](https://meta.discourse.org/t/add-images-to-api-posts/204651/3 "2022-01-14T18:44:59Z")

</div>

파일을 업로드한 후 파일의 URL을 가져와서 게시해야 합니다.

```plaintext
r = requests.put()
p = "http:"+r.json()['url']

```

> [@Discourse API 업로드](https://meta.discourse.org/t/discourse-api-uploads/134545/2?u=mapengfei-nwpu):
>
> This worked for me: r = requests.post(f'{rooturl}/uploads.json', files = {'files[]': (file, open(file, 'rb'), 'image/png')}, data={'type':'image'}, headers={ "Api-Username" : sys.argv[1], "Api-Key" : sys.argv[2], }) Probably, content-type': 'multipart/form-data' should be omitted so the requests library can figure out what to.

---

_[View the full topic](https://meta.discourse.org/t/add-images-to-api-posts/204651)._
