milesj / uploader

[Deprecated] A CakePHP plugin for file uploading and validating.
MIT License
193 stars 73 forks source link

Rackspace Cloudfiles are not deleted or cleaned up #194

Open challgren opened 7 years ago

challgren commented 7 years ago

Rackspace Cloudfiles aren't deleted because the name of the object sent to Cloudfiles is the full URL which isn't a valid name since the format expected is {folder}/{name} or {name}. I know this project is no longer maintaned but for other people having the same issue the solution is to edit AttachmentBehavior.php around line 747 and change the following code

$transporter = $this->_getTransporter($attachment, $attachment['transport']);

return $transporter->delete($path);

to

$transporter = $this->_getTransporter($attachment, $attachment['transport']);
if ($attachment['transport']['class'] == 'cloudfiles') {
    $url = parse_url($path);
    $path = ltrim($url['path'], '/');
}
return $transporter->delete($path);

I was going to make the code folder specific but this code allows images to be deleted in moved the container to different folders. For example you first put the image in the folder Items and then decide to change the folder to products. Old records that point to items will still be deleted.