QuickBlox - How to use REST API + PHP to create blob content

I tried to create blob content (image) using the QuickBlox REST API (curl) and PHP, the response always returns "size": zero, and the image does not load into the QuickBlox backend, that is, it displays "Not loaded" in the QuickBlox Administration Portal.

I think maybe the file name is not passed in correctly by the API, but the QuickBlox REST API document is too simple and I could not understand.

Below is my code, much appreciated if anyone can help, thanks a lot:

JS:

function upload_profile_photo() { var data = new FormData(); jQuery.each(jQuery('.editableform input[name=avatar]')[0].files, function(i, file) { data.append('file-'+i, file); }); jQuery.ajax({ url: 'update_profile_photo.php', data: data, cache: false, contentType: false, processData: false, type: 'POST', success: function(result){ showSuccess(result); } }); } 

update_profile_photo.php:

 ... $imageName = $_FILES['file-0']['tmp_name']; // Tried ['name'] also failed $imageType = $_FILES['file-0']['type']; ... $response = UpdateProfileImage($imageType, $imageName); ... function UpdateProfileImage($imageType, $imageName) { $requestBody = http_build_query(array( 'blob' => array( 'content_type' => $imageType, 'name' => $imageName ) )); ... $response = $this->Curl_Post($requestHeader, $requestName, $requestBody); return $response; } 

QuickBlox answer:

 {"blob":{"id":1159901,"uid":"d328c47565614cbdaed9671ce7bc6d8000", "content_type":"image/jpeg","name":"/tmp/phpbRqnXb","size":null, ...} 
+5
source share
1 answer

To upload a file to QuickBlox, you must make 3 requests, as indicated here:

http://quickblox.com/developers/Content#Typical_use_.D1.81ases

  • Create file
  • Upload file
  • Upload file declaration

After that, your file will be fully loaded into the QuickBlox backend, and you can check it in the admin panel

+2
source

All Articles