Oau22. how does one upload files through APIS?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.