How to get uploaded image url using the Discourse API?

Get rid of the function http_build_query, we can upload image successfully!

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

  $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.:slightly_smiling: