我尝试使用QuickBlox REST API(curl)和PHP创建blob内容(图像),响应返回始终显示"size":null,并且图像未上传到QuickBlox后端,即在QuickBlox管理门户中显示"未上载" .
我想可能文件名没有正确传递给API,但QuickBlox REST API文档太简单了,我无法理解.
以下是我的代码,非常感谢,如果有人可以提供帮助,非常感谢:
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
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
) …Run Code Online (Sandbox Code Playgroud)