# How to get uploaded image url using the Discourse API?

**URL:** <https://meta.discourse.org/t/how-to-get-uploaded-image-url-using-the-discourse-api/37800>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [January 12, 2016, 3:51am UTC](https://meta.discourse.org/t/how-to-get-uploaded-image-url-using-the-discourse-api/37800 "2016-01-12T03:51:27Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![sleep](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sleep/32/48342_2.png) [@sleep](https://meta.discourse.org/u/sleep)\
**Post date:** [January 16, 2016, 2:21pm UTC](https://meta.discourse.org/t/how-to-get-uploaded-image-url-using-the-discourse-api/37800/12 "2016-01-16T14:21:52Z")

</div>

Get rid of the function http\_build\_query, we can upload image successfully!

```php
public function upload_file($user) {
  $url = 'http://hostname/uploads?api_key=api_key&api_username=api_username';
  $poststr = http_build_query(array('username' => $user, 'type' => 'image', 'file' => '/uploads/file/filename', 'synchronous' => 'true')); // get rid of the function http_build_query, we can upload image successfully!
  $data = _curl($url, $poststr)); // _curl() : a custom function 
  return $data;
}

```

After change

```php
  $poststr = array('username' => $user, 'type' => 'image', 'file' => '/uploads/file/filename', 'synchronous' => 'true'); // get rid of the function http_build_query, we can upload image successfully!

```

In summary, when we submit data to discourse server using curl, we may use three method to post parameters. You should try more methods when you encounter problems.

one: json  
two: http\_query\_query  
three: array

There may be more.🙂

---

_[View the full topic](https://meta.discourse.org/t/how-to-get-uploaded-image-url-using-the-discourse-api/37800)._
