markguinn / silverstripe-cloudassets

Allows some or all of the assets folder to be located in a cloud storage container (S3, CloudFiles, etc.)
MIT License
19 stars 9 forks source link

CMS upload fails for images when LocalCopy=false #14

Closed markguinn closed 10 years ago

markguinn commented 10 years ago

The problem is that UploadField creates an Image object, which is then wrapped to CloudImage, but the initial reference is still an Image. This is a weakness in the architecture that I don't know how to overcome at this stage. The following code then fails in UploadField.php (currently line 911 - the call to SetRatioSize returns null because the width and height are not set):

    /**
     * @param File $file
     * @return string
     */
    protected function getThumbnailURLForFile(File $file) {
        if ($file->exists() && file_exists(Director::baseFolder() . '/' . $file->getFilename())) {
            $width = $this->getPreviewMaxWidth();
            $height = $this->getPreviewMaxHeight();
            if ($file->hasMethod('getThumbnail')) {
                return $file->getThumbnail($width, $height)->getURL();
            } elseif ($file->hasMethod('getThumbnailURL')) {
                return $file->getThumbnailURL($width, $height);
            } elseif ($file->hasMethod('SetRatioSize')) {
                return $file->SetRatioSize($width, $height)->getURL();
            } else {
                return $file->Icon();
            }
        }
        return false;
    }

Options:

  1. Implement getThumbnail in CloudFileExtension. This would cover the above case but I'm uncomfortable with it b/c it feels hack-y.
  2. Set $this->width and $this->height on the source image object during the wrapping process. This would cause SetRatioSize to at minimum return a CloudImageMissing placeholder. Again, not ideal.
  3. Do the upload offline - either by requiring the QueuedJobs module or an additional cron job. I really don't want to have to do this.
  4. Try to extend UploadField.