I'm using the Uploadcare multi-upload widget and get a group ID back on post. When I call the API to list the files in the group, I want to extract certain pieces of information about each file (uuid, mime_type, original_filename, etc).
Here is my code:
$privateFiles = $_REQUEST['privateFiles'];
$ucApi = new Uploadcare\Api(public_key_removed, private_key_removed);
$group = $ucApi->getGroup($privateFiles);
$files = $group->getFiles();
foreach ($files as $ucFile)
{
echo $ucFile['uuid'];
}
When I try to do this, I receive this error:
Fatal error: Cannot use object of type Uploadcare\File as array
I'm definitely getting the data back from the API but just having an issue trying to parse it. Here's a sample of what I'm getting back:
Array ( [0] => Uploadcare\File Object ( [re_uuid_with_effects:Uploadcare\File:private] => !/?(?P[a-z0-9]{8}-(?:[a-z0-9]{4}-){3}[a-z0-9]{12})(?:/(?:-/(?P(?:[^/]+/)+)))?(?[^/]*)! [uuid:Uploadcare\File:private] => 47ff1aa0-eebe-43d0-8803-0578455e82a1 [operations:Uploadcare\File:private] => Array ( ) [api:Uploadcare\File:private] => Uploadcare\Api Object ( [public_key:Uploadcare\Api:private] => public_key_removed [secret_key:Uploadcare\Api:private] => private_key_removed [api_host:Uploadcare\Api:private] => api.uploadcare.com [current_method:Uploadcare\Api:private] => GET [cdn_host] => ucarecdn.com [cdn_protocol] => https [retry_throttled:Uploadcare\Api:private] => 1 [userAgentName:Uploadcare\Api:private] => PHP Uploadcare Module [widget] => Uploadcare\Widget Object ( [api:Uploadcare\Widget:private] => Uploadcare\Api Object *RECURSION* ) [uploader] => Uploadcare\Uploader Object ( [host:Uploadcare\Uploader:private] => upload.uploadcare.com [api:Uploadcare\Uploader:private] => Uploadcare\Api Object *RECURSION* ) [version] => 1.5.5/5.6 [api_version] => 0.4 [defaultFilters:Uploadcare\Api:private] => Array ( [file] => Array ( [stored] => [removed] => ) ) ) [operation_list:Uploadcare\File:private] => Array ( [0] => crop [1] => resize [2] => scale_crop [3] => effect [4] => preview ) [cached_data:Uploadcare\File:private] => Array ( [uuid] => 47ff1aa0-eebe-43d0-8803-0578455e82a1 [original_file_url] => https://ucarecdn.com/47ff1aa0-eebe-43d0-8803-0578455e82a1/processes.txt [image_info] => [mime_type] => text/plain [is_ready] => 1 [url] => https://api.uploadcare.com/files/47ff1aa0-eebe-43d0-8803-0578455e82a1/ [original_filename] => processes.txt [datetime_uploaded] => 2016-10-20T19:28:44.314526Z [size] => 8543 [is_image] => [datetime_stored] => [datetime_removed] => [source] => [default_effects] => ) [default_effects] => [filename] => ) [1] => Uploadcare\File Object ( [re_uuid_with_effects:Uploadcare\File:private] => !/?(?P[a-z0-9]{8}-(?:[a-z0-9]{4}-){3}[a-z0-9]{12})(?:/(?:-/(?P(?:[^/]+/)+)))?(?[^/]*)! [uuid:Uploadcare\File:private] => 76e4fbca-0133-4863-838f-43b3e47a892e [operations:Uploadcare\File:private] => Array ( ) [api:Uploadcare\File:private] => Uploadcare\Api Object ( [public_key:Uploadcare\Api:private] => public_key_removed [secret_key:Uploadcare\Api:private] => private_key_removed [api_host:Uploadcare\Api:private] => api.uploadcare.com [current_method:Uploadcare\Api:private] => GET [cdn_host] => ucarecdn.com [cdn_protocol] => https [retry_throttled:Uploadcare\Api:private] => 1 [userAgentName:Uploadcare\Api:private] => PHP Uploadcare Module [widget] => Uploadcare\Widget Object ( [api:Uploadcare\Widget:private] => Uploadcare\Api Object *RECURSION* ) [uploader] => Uploadcare\Uploader Object ( [host:Uploadcare\Uploader:private] => upload.uploadcare.com [api:Uploadcare\Uploader:private] => Uploadcare\Api Object *RECURSION* ) [version] => 1.5.5/5.6 [api_version] => 0.4 [defaultFilters:Uploadcare\Api:private] => Array ( [file] => Array ( [stored] => [removed] => ) ) ) [operation_list:Uploadcare\File:private] => Array ( [0] => crop [1] => resize [2] => scale_crop [3] => effect [4] => preview ) [cached_data:Uploadcare\File:private] => Array ( [uuid] => 76e4fbca-0133-4863-838f-43b3e47a892e [original_file_url] => https://ucarecdn.com/76e4fbca-0133-4863-838f-43b3e47a892e/XPlaneInstallerLog.txt [image_info] => [mime_type] => text/plain [is_ready] => 1 [url] => https://api.uploadcare.com/files/76e4fbca-0133-4863-838f-43b3e47a892e/ [original_filename] => X-Plane Installer Log.txt [datetime_uploaded] => 2016-10-20T19:28:44.332926Z [size] => 5526 [is_image] => [datetime_stored] => [datetime_removed] => [source] => [default_effects] => ) [default_effects] => [filename] => ) )
答案 0 :(得分:0)
Uploadcare\File
是一个对象,所以你应该像对待它一样。
要获得UUID,有一种方法:$file->getUuid()
。
对于其他元数据,您可以use data
数组:
foreach ($files as $file)
{
echo $file->getUuid();
echo $file->data['is_image'];
echo $file->data['datetime_uploaded'];
// etc
}