Skip to content

Commit

Permalink
Fixing CORS issue with S3 and canvas (resize/crop), canvas complains …
Browse files Browse the repository at this point in the history
…about using "tainted" files if using S3, because of cross origin. Have to use AWS S3 console, and set a CORS policy on your bucket.
  • Loading branch information
cheesegrits committed Dec 4, 2017
1 parent 601d536 commit bf6aa94
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions plugins/fabrik_element/fileupload/adaptors/amazons3sdkstorage.php
Expand Up @@ -15,6 +15,7 @@

use Aws\Exception\AwsException;
use Aws\S3\Exception\S3Exception;
use GuzzleHttp\Psr7;


/**
Expand Down Expand Up @@ -207,6 +208,7 @@ private function bucketExists()
public function upload($tmpFile, $filepath)
{
$filepath = str_replace("\\", '/', $filepath);
$mimeType = GuzzleHttp\Psr7\mimetype_from_filename($filepath);

if (!$this->bucketExists())
{
Expand Down Expand Up @@ -240,7 +242,8 @@ public function upload($tmpFile, $filepath)
'SourceFile' => $tmpFile,
'Bucket' => $this->getBucketName(),
'Key' => $this->urlToKey($filepath),
'ACL' => $this->getAcl()
'ACL' => $this->getAcl(),
'ContentType' => $mimeType
];

if ($this->isEncrypted())
Expand Down Expand Up @@ -724,6 +727,11 @@ public function getFullPath($filepath)

public function preRenderPath($filepath)
{
if (empty($filepath))
{
return '';
}

$params = $this->getParams();
static $presigned = array();

Expand All @@ -735,7 +743,8 @@ public function preRenderPath($filepath)
{
$cmd = $this->s3->getCommand('GetObject', [
'Bucket' => $this->getBucketName(),
'Key' => $this->urlToKey($filepath)
'Key' => $this->urlToKey($filepath),
'ResponseCacheControl' => "no-cache"
]);
$request = $this->s3->createPresignedRequest($cmd, '+' . $lifetime . ' seconds');
$presigned[$filepath] = (string) $request->getUri();
Expand Down

0 comments on commit bf6aa94

Please sign in to comment.