The environment is: yii2-authclientweibo.upload interface thanks to the idea of dial, this problem should not be limited in the yii2 framework. interface document: pic type: binary description: The image to be uploaded. Only JPEG, GIF, and PNG formats are supported. The image size is smaller than 5 MB. My code: {code...}... environment is:
- Yii2-authclient
- Weibo. upload interface
Thanks for your ideas/tips. This issue should not be limitedyii2Within the framework.
Interface document:
picType: binary description: The image to be uploaded. Only JPEG, GIF, and PNG formats are supported. The image size is smaller than 5 MB.
My code:
public function sendUpload($text, $url){ return $this->api('2/statuses/upload.json', 'POST', [ 'status' => $text, 'visible' => self::VISIBLE_ALL, 'pic' => '@'.$url, 'source' => $this->source, ]);}
Error returned after execution:
{"error":"unsupport mediatype (application/x-www-form-urlencoded)","error_code":10007,"request":"/2/statuses/upload.json"}
DEMO code provided by Weibo:
function upload( $status, $pic_path, $lat = NULL, $long = NULL ){ $params = array(); $params['status'] = $status; $params['pic'] = '@'.$pic_path; if ($lat) { $params['lat'] = floatval($lat); } if ($long) { $params['long'] = floatval($long); } return $this->oauth->post( 'statuses/upload', $params, true );}
Reply content:
Environment:
- Yii2-authclient
- Weibo. upload interface
Thanks for your ideas/tips. This issue should not be limitedyii2Within the framework.
Interface document:
picType: binary description: The image to be uploaded. Only JPEG, GIF, and PNG formats are supported. The image size is smaller than 5 MB.
My code:
public function sendUpload($text, $url){ return $this->api('2/statuses/upload.json', 'POST', [ 'status' => $text, 'visible' => self::VISIBLE_ALL, 'pic' => '@'.$url, 'source' => $this->source, ]);}
Error returned after execution:
{"error":"unsupport mediatype (application/x-www-form-urlencoded)","error_code":10007,"request":"/2/statuses/upload.json"}
DEMO code provided by Weibo:
function upload( $status, $pic_path, $lat = NULL, $long = NULL ){ $params = array(); $params['status'] = $status; $params['pic'] = '@'.$pic_path; if ($lat) { $params['lat'] = floatval($lat); } if ($long) { $params['long'] = floatval($long); } return $this->oauth->post( 'statuses/upload', $params, true );}
You need multipart/form-data.
For details, refer to this gist.