5

I tried to create blob content (an image) with QuickBlox REST API(curl) and PHP, the response return always says "size":null, and image is not uploaded to QuickBlox backend, i.e. shows "Not uploaded" in QuickBlox admin portal.

I guess maybe the file name is not properly passed to the API, but the QuickBlox REST API document is too simple and I couldn't figure out.

Below is my code, much appreciated if anyone could help, many thanks:

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 Response:

{"blob":{"id":1159901,"uid":"d328c47565614cbdaed9671ce7bc6d8000",
"content_type":"image/jpeg","name":"/tmp/phpbRqnXb","size":null, ...}

1 Answer 1

1

To upload a file to QuickBlox you have to do 3 requests as mentioned here:

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

  1. Create a file
  2. Upload a file
  3. Declaring file uploaded

After this your file will be completely uploaded to the QuickBlox backend and you will be able to check it in Admin panel

Sign up to request clarification or add additional context in comments.

3 Comments

How the binary needs to be uploaded? the doc says that -F file=@user_avatar.jpeg but that's the name of the file or the actual file blob as form data?
It should be a common way to upload a file in PHP
Hello have you any code demo of php for uploading file ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.