doushen8391 2016-08-09 09:36
浏览 18

如何使用php api更新QuickBlox中的用户个人资料图片?

How to update user profile picture in Quickblox using php codeigntier ?

Documentation found at

http://quickblox.com/developers/Users

  • 写回答

1条回答 默认 最新

  • dto52236 2017-02-07 11:24
    关注

    after found rest api i have found the solution for how to upload profile picture to quickblox user.

    there are three 3 steps for uploading content as per quickblox rest api First you generate token from the quickblox and then perform these 3 steps

    1. Create file

    https://quickblox.com/developers/Content#Create_a_file

      $strFilename = '2.jpeg';
      $post_body = http_build_query(array(
            'blob[content_type]' => 'image/jpeg',
            'blob[name]' =>$strFilename,
        ));
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT.'blobs.json');
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Accept: application/json',
            'Content-Type: application/x-www-form-urlencoded',
            'QuickBlox-REST-API-Version: 0.1.0',
            'QB-Token: ' . $token
        ));
        $response = curl_exec($curl);
        $error = curl_error($curl);
    
    
        if ($response) {
                return $response;
        } else {
                return false;
        }
        curl_close($curl);
    

    After this curl call you have got the response and in response got the response like this

    [blob] => Array
        (
            [id] => 7178102
            [uid] => f9cc9d7938c4468f8bdccdcb68fb5d8c00
            [content_type] => image/jpeg
            [name] => 2.jpeg
            [size] => 
            [created_at] => 2017-02-07T10:35:38Z
            [updated_at] => 2017-02-07T10:35:38Z
            [ref_count] => 1
            [blob_status] => 
            [set_completed_at] => 
            [public] => 1
            [last_read_access_ts] => 
            [lifetime] => 8600
            [account_id] => 56721
            [app_id] => 
            [blob_object_access] => Array
                (
                    [id] => 7178102
                    [blob_id] => 7178102
                    [expires] => 2017-02-07T11:35:38Z
                    [object_access_type] => Write
                    [params] => https://qbprod.s3.amazonaws.com/?Content-Type=image%2Fjpeg&Expires=Tue%2C%2007%20Feb%202017%2011%3A35%3A38%20GMT&acl=public-read&key=f9cc9d7938c4468f8bdccdcb68fb5d8c00&policy=eyJleHBpcmF0aW9uIjoiMjAxNy0wMi0wN1QxMTozNTozOFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJxYnByb2QifSx7ImFjbCI6InB1YmxpYy1yZWFkIn0seyJDb250ZW50LVR5cGUiOiJpbWFnZS9qcGVnIn0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDEifSx7IkV4cGlyZXMiOiJUdWUsIDA3IEZlYiAyMDE3IDExOjM1OjM4IEdNVCJ9LHsia2V5IjoiZjljYzlkNzkzOGM0NDY4ZjhiZGNjZGNiNjhmYjVkOGMwMCJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUFJWTdLRk0yM1hHWEo3UjdBLzIwMTcwMjA3L3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWFsZ29yaXRobSI6IkFXUzQtSE1BQy1TSEEyNTYifSx7IngtYW16LWRhdGUiOiIyMDE3MDIwN1QxMDM1MzhaIn1dfQ%3D%3D&success_action_status=201&x-amz-algorithm=AWS4-HMAC-SHA256&x-amz-credential=AKIAIY7KFM23XGXJ7R7A%2F20170207%2Fus-east-1%2Fs3%2Faws4_request&x-amz-date=20170207T103538Z&x-amz-signature=5e236c3da60a922951c8ab6281ae82af3a88e37c15d8630ad6ff590610a87fd8
                )
    
        )
    
    1. Upload file

    so you have to used the params url parameters and make another call for uploading file

    $strFilename = '2.jpeg';
        $url = 'https://qbprod.s3.amazonaws.com/';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array(
            'Content-Type' => $arr['Content-Type'],
            'Expires'=>$arr['Expires'],
            'acl'=>$arr['acl'],
            'key'=>$arr['key'],
            'policy'=>$arr['policy'],
            'success_action_status'=>$arr['success_action_status'],
            'x-amz-algorithm'=>$arr['x-amz-algorithm'],
            'x-amz-credential'=>$arr['x-amz-credential'],
            'x-amz-date'=>$arr['x-amz-date'],
            'x-amz-signature'=>$arr['x-amz-signature'],
            'file' => new CurlFile('2.jpeg', $arr['Content-Type'], $strFilename)
        ));
        $response = curl_exec($ch);
        if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 204) {
            echo 'Success!';
        } else {
            $error = substr($response, strpos($response, '<Code>') + 6);
            echo substr($error, 0, strpos($error, '</Code>'));
        }
        return $response;
    

    so by using this code your content file will be uploaded and you got the location of the file and used as profile picture or etc .

    1. Declare file

      $ch = curl_init();
      
      curl_setopt($ch, CURLOPT_URL, "http://api.quickblox.com/blobs/" . $strId . "/complete.xml");  // strId is blod id return by 1 step
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, "blob[size]=10000"); //your file size
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
      
      
       $headers = array();
       $headers[] = "Quickblox-Rest-Api-Version: 0.1.0";
        $headers[] = "Qb-Token: " . $token;
       $headers[] = "Content-Type: application/x-www-form-urlencoded";
       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      
       $result = curl_exec($ch);
       if (curl_errno($ch)) {
           echo 'Error:' . curl_error($ch);
       }
        curl_close($ch);
        return $result;
      

    Please let me know the any issue regards the same. Thanks

    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口