title: Quickblox: User Image or Avatar is Uploaded succesfully via API but not previewing in quickblox admin panel?
body: <p>Quickblox admin panel in content section images status is Uploaded but nethier image is previewing nor the AWS(amazons3) link is working.</p>
  
  <p>Step 1- Created session using quickblox account(main account) and get session token from response.</p>
  
  <p>Step 2- Log in API user using user credentials and session token.</p>
  
  <p>Step 3- Created a blob and and from response extracted all the blob info param and made a json array.</p>
  
  <p>Step 4- Uploaded user image / avatar and getting response</p>
  
  <pre><code>    HTTP/1.1 100 Continue
  
  HTTP/1.1 201 Created
  x-amz-id-2: CaF37TJwdt0PZjGdquV4yQSeNqtDyWrZge1DfkBinhNdhHYb635nsWcECFhUoRgiYzuAAxf+z2Q=
  x-amz-request-id: F24A002779D03E34
  Date: Tue, 21 Mar 2017 13:15:17 GMT
  ETag: "3b45dadd80ddb4019e129e1c8469ca40"
  Location: http://qbprod.s3.amazonaws.com/2e5b9610a6ff4a8395ade21377def2f500
  Content-Type: application/xml
  Content-Length: 269
  Server: AmazonS3
  </code></pre>
  
  <p>Step 5- Declared File uploaded.</p>
  
  <p>Step 6- Connected blob id to API user.</p>
  
  <p>Here is my all code, tell me what i am doing wrong: </p>
  
  <p>note: login credentials are not real.</p>
  
  <pre><code>&lt;?php
  
              $quickblox_user_name = "quickblox_agicent"; //quickblox account
              $quickblox_password = "quickblox@123";
  
              $user_login = "quickblox_qb_130"; //API 
              $user_pwd = "21663496";
  
              $profile_pic = "c.png"; // image path
              $file_size = filesize($profile_pic);
  
              //CREATE SESSION
              $session = createSession($quickblox_user_name,$quickblox_password);
              $token = $session-&gt;token;
  
              //LOGIN USER
              $login_user        =    loginUser($user_login,$user_pwd,$token);
              $login_user_decode  =   json_decode($login_user);   
              $log_in                =    $login_user_decode-&gt;user;
              $user_id              =     $log_in-&gt;id;
  
              //CREATE A BLOB
              $create_blob   =    createBlob($profile_pic, $token);
              $res           =    json_decode($create_blob)-&gt;blob;
  
              $blob_id       =    $res-&gt;id;
              $name         =     $res-&gt;name;
              $size         =     $res-&gt;size;
              $res_en         =   json_encode($res-&gt;blob_object_access);
              $rr             =   json_decode($res_en);
              $get_params =   $rr-&gt;params;
  
              //EXTRACTING BLOB PARAMETER FROM QUERY STRING       
              $Query_String            = explode("&amp;", explode("?", $get_params)[1] );
              $content_type            = urldecode(substr($Query_String[0], strpos($Query_String[0], "=") + 1));
              $expires                  = urldecode(substr($Query_String[1], strpos($Query_String[1], "=") + 1));
              $acl                      = substr($Query_String[2], strpos($Query_String[2], "=") + 1);
              $key                      = substr($Query_String[3], strpos($Query_String[3], "=") + 1);
              $policy                    = substr($Query_String[4], strpos($Query_String[4], "=") + 1);
              $success_action_status  = substr($Query_String[5], strpos($Query_String[5], "=") + 1);
              $x_amz_algorithm          = substr($Query_String[6], strpos($Query_String[6], "=") + 1);
              $x_amz_credential        = urldecode(substr($Query_String[7], strpos($Query_String[7], "=") + 1));
              $x_amz_date                = substr($Query_String[8], strpos($Query_String[8], "=") + 1);
              $x_amz_signature          = substr($Query_String[9], strpos($Query_String[9], "=") + 1);
  
              //CREATE JSON ARRAY OF EXTRATED PARAMETER    
              $fields = array
              (
                  "Content-Type"           =&gt; $content_type,
                  "Expires"                 =&gt; $expires,                 
                  "acl"                     =&gt; $acl,
                  "key"                     =&gt; $key,
                  "policy"                   =&gt; $policy,
                  "success_action_status" =&gt; $success_action_status,
                  "x-amz-algorithm"         =&gt; $x_amz_algorithm,
                  "x-amz-credential"       =&gt; $x_amz_credential,
                  "x-amz-date"               =&gt; $x_amz_date,
                  "x-amz-signature"         =&gt; $x_amz_signature,
                  "file"                   =&gt; "@".$profile_pic
              );
  
              //UPLOAD AVATAR / IMAGE     
              $upload_avatar = uploadAvatar($fields);
              $resPP       = json_decode($upload_avatar);
  
              //DECLARE FILE UPLOAD
              $declare_upload_avatar = declareUploadAvatar($file_size,$blob_id,$token);
  
              //CONNECT BLOB ID TO API USER
              $resultConnect = connectBlobToUser($blob_id,$user_id,$token);
  
  
  
          //FUNCTIONS 
          function createSession($login,$pwd)
          {
               // Application credentials - change to yours (found in QB Dashboard)
               DEFINE('APPLICATION_ID', 12345);
               DEFINE('AUTH_KEY', "MDJ8979q328");
               DEFINE('AUTH_SECRET', 'asDCE-JLDJCEU');
               DEFINE("RESETPWD_BASE_URL", strtolower(stristr($_SERVER["SERVER_PROTOCOL"], "/", true)) . "://" . $_SERVER["HTTP_HOST"] ."/img");
  
               // User credentials
               DEFINE('USER_LOGIN', $login);
               DEFINE('USER_PASSWORD', $pwd);
  
               // Quickblox endpoints
               DEFINE('QB_API_ENDPOINT', "https://api.quickblox.com");
               DEFINE('QB_PATH_SESSION', "session.json");
  
               // Generate signature
               $nonce = rand();
               $timestamp = time();
               $signature_string = "application_id=".APPLICATION_ID."&amp;auth_key=".AUTH_KEY."&amp;nonce=".$nonce."&amp;timestamp=".$timestamp."&amp;user[login]=".USER_LOGIN."&amp;user[password]=".USER_PASSWORD;
  
               $signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
  
               $post_body = "application_id=" . APPLICATION_ID . "&amp;auth_key=" . AUTH_KEY . "&amp;timestamp=" . $timestamp . "&amp;nonce=" . $nonce . "&amp;signature=" . $signature . "&amp;user[login]=" . USER_LOGIN . "&amp;user[password]=" . USER_PASSWORD;
  
               // Configure cURL
               $curl = curl_init();
               curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT . '/' . QB_PATH_SESSION); // Full path is - https://api.quickblox.com/session.json
               curl_setopt($curl, CURLOPT_POST, true); // Use POST
               curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
               curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
               curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
               curl_setopt($curl, CURLOPT_CAINFO,RESETPWD_BASE_URL."/quickblox.com.crt");
  
               // Execute request and read response
               $response = curl_exec($curl);
               $responseJSON = json_decode($response);
               // Check errors
               if ($response) 
               {
                   $rs = json_decode($response)-&gt;session;
                   return $rs;
  
               } else {
                   echo "0";
                     //  $error = curl_error($curl). '(' .curl_errno($curl). ')';
                     //  echo $error . "\n";
               }
  
               // Close connection
               curl_close($curl);
  
          }
  
          function loginUser($login1,$pwd1,$token)
          {
              $requestCred =  '{"login": "'.$login1.'", "password": "'.$pwd1.'"}'; 
  
              $ch = curl_init('http://api.quickblox.com/login.json');
              curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
              curl_setopt($ch, CURLOPT_POSTFIELDS, $requestCred);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
              curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                          'Content-Type: application/json',
                          'QuickBlox-REST-API-Version: 0.1.1',
                          'QB-Token: ' . $token
                      ));
              $res = curl_exec($ch);
              curl_close( $ch );  
  
              return $res;
          }
  
          function createBlob($profile_pic,$token)
          {
              $ext               =    pathinfo($profile_pic, PATHINFO_EXTENSION);
              if($ext == 'png' || $ext == "Png" || $ext == "PNG")
                  $request =  '{"blob": {"content_type": "image/png", "name": "'.$profile_pic.'", "public": "true"}}';    
              else
                  $request =  '{"blob": {"content_type": "image/jpeg", "name": "'.$profile_pic.'"}}'; 
  
                  $ch = curl_init('http://api.quickblox.com/blobs.json');
                  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
                  curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                      'Content-Type: application/json',
                      'QuickBlox-REST-API-Version: 0.1.1',
                      'QB-Token: ' . $token
                  ));
                  $res = curl_exec($ch);
                  curl_close( $ch );  
  
                  return $res;
          }
  
          function uploadAvatar($fields)
          {
                  $ch = curl_init('http://qbprod.s3.amazonaws.com/');
                  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,  $fields );
                  $res = curl_exec($ch);
                  curl_close( $ch );
  
                  return $res;
          }
  
          function declareUploadAvatar($file_size,$blob_id,$token)
          {
                  $request_size =     '{"blob": {"size": '.$file_size.'}}';
                  $ch = curl_init("http://api.quickblox.com/blobs/".$blob_id."/complete.json/");
                  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
                  curl_setopt($ch, CURLOPT_POSTFIELDS,  $request_size );
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                      'Content-Type: application/json',
                      'QuickBlox-REST-API-Version: 0.1.1',
                      'QB-Token: ' . $token
                  ));
                  $res = curl_exec($ch);
                  curl_close( $ch );  
  
                  return $res;
          }
  
          function connectBlobToUser($blob_id,$user_id,$token)
          {
                  $update_user =  '{"user": {"blob_id": '.$blob_id.'}}';
                  $ch = curl_init("http://api.quickblox.com/users/$user_id.json/");
                  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
                  curl_setopt($ch, CURLOPT_POSTFIELDS,  $update_user );
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                      'Content-Type: application/json',
                      'QuickBlox-REST-API-Version: 0.1.1',
                      'QB-Token: ' . $token
                  ));
                  $res = curl_exec($ch);
                  curl_close( $ch );
  
                  return $res;
          }
  
          ?&gt;
  </code></pre>