markguinn / silverstripe-cloudassets Goto Github PK
View Code? Open in Web Editor NEWAllows some or all of the assets folder to be located in a cloud storage container (S3, CloudFiles, etc.)
License: MIT License
Allows some or all of the assets folder to be located in a cloud storage container (S3, CloudFiles, etc.)
License: MIT License
hello guys i just wrote a new swift driver, here is the link
https://github.com/smarcet/silverstripe-cloudassets-swift
cheers
Hi, I've got this working using Heroku and the S3 driver. The only issue I've noticed is that clicking 'Sync Files' is okay while the files are still on disk, but after a deploy/restart, clicking that will remove all cloud assets from the file browser. The button doesn't really make sense with this type of setup, so it would probably make sense to hide it, but I'm wondering if it's just a problem with my set up?
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:
I'm not sure if anybody else has had this issue, but for me, as soon as my EC2 instance rebooted or scaled, images were lost.
I tracked it down to line 122 of CloudImage, the getFormattedImage function (Worth also adding to the doc that this ONLY works with that perhaps? E.G - CroppedImage etc all just fall back to standard Image.)
So that line seems to check if the file exists locally before doing anything else, which in most cases, it doesn't.
if ($this->ID && $this->Filename && Director::fileExists($this->Filename)) {
I changed that to
if ($this->ID && $this->Filename)) {
and now this works fine for me. As soon as I clear my assets folder on disk, it downloads every item again from S3, then resamples them and stores them correctly.
This seems to only happen with resized images. Need to figure out what the case is for this to happen though because when it does happen you have to manually delete the remote file.
Hi, when i try to upload file with $has_one 'VideoFile' => 'File' i've this error:
Object->__call(): the method 'parent' does not exist on 'File'
How can i fix it?
Hi,
I am trying to setup this add-on, but when I am uploading an image in the CMS I am getting:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Not sure how to solve that.
Also on https://github.com/edlinklater/silverstripe-cloudassets-s3 the .yml is setup with api key and api secret and this add-on is using username and apikey. which one should I use?
thanks you!
Would need:
Below is the dump, this is originating from /admin/pages/edit/EditorToolbar/viewfile but only happens when the asset is uploaded to S3
ERROR [Warning]: curl_setopt(): supplied argument is not a valid File-Handle resource
IN GET /admin/pages/edit/EditorToolbar/viewfile?ID=92
Line 247 in /Users/drye/Development/Crossroads/Milacron/SS-CMS/framework/api/RestfulService.php
Source
======
238: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
239: curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
240: curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->getConnectTimeout());
241: if(!ini_get('open_basedir')) curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
242: curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
243:
244:
245: // Write headers to a temporary file
246: $headerfd = tmpfile();
* 247: curl_setopt($ch, CURLOPT_WRITEHEADER, $headerfd);
248:
249: // Add headers
250: if($this->customHeaders) {
251: $headers = array_merge((array)$this->customHeaders, (array)$headers);
252: }
253:
Trace
=====
curl_setopt(Resource id #429,10029,)
RestfulService.php:247
RestfulService->curlRequest(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png,GET,,,Array)
RestfulService.php:195
RestfulService->request()
Oembed.php:107
Oembed::autodiscover_from_url(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png)
Oembed.php:147
Oembed::get_oembed_from_url(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png)
HtmlEditorField.php:928
HtmlEditorField_Embed->__construct(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png,CloudImage)
HtmlEditorField.php:516
HtmlEditorField_Toolbar->viewfile(SS_HTTPRequest)
RequestHandler.php:288
RequestHandler->handleAction(SS_HTTPRequest,viewfile)
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
RequestHandler.php:222
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel)
LeftAndMain.php:443
LeftAndMain->handleRequest(SS_HTTPRequest,DataModel)
AdminRootController.php:93
AdminRootController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:370
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:153
Director::direct(/admin/pages/edit/EditorToolbar/viewfile,DataModel)
main.php:177
ERROR [Warning]: rewind() expects parameter 1 to be resource, boolean given
IN GET /admin/pages/edit/EditorToolbar/viewfile?ID=92
Line 284 in /Users/drye/Development/Crossroads/Milacron/SS-CMS/framework/api/RestfulService.php
Source
======
275: curl_setopt_array($ch, $this->proxy);
276: }
277:
278: // Set any custom options passed to the request() function
279: curl_setopt_array($ch, $curlOptions);
280:
281: // Run request
282: $body = curl_exec($ch);
283:
* 284: rewind($headerfd);
285: $headers = stream_get_contents($headerfd);
286: fclose($headerfd);
287:
288: $response = $this->extractResponse($ch, $headers, $body);
289: curl_close($ch);
290:
Trace
=====
rewind()
RestfulService.php:284
RestfulService->curlRequest(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png,GET,,,Array)
RestfulService.php:195
RestfulService->request()
Oembed.php:107
Oembed::autodiscover_from_url(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png)
Oembed.php:147
Oembed::get_oembed_from_url(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png)
HtmlEditorField.php:928
HtmlEditorField_Embed->__construct(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png,CloudImage)
HtmlEditorField.php:516
HtmlEditorField_Toolbar->viewfile(SS_HTTPRequest)
RequestHandler.php:288
RequestHandler->handleAction(SS_HTTPRequest,viewfile)
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
RequestHandler.php:222
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel)
LeftAndMain.php:443
LeftAndMain->handleRequest(SS_HTTPRequest,DataModel)
AdminRootController.php:93
AdminRootController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:370
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:153
Director::direct(/admin/pages/edit/EditorToolbar/viewfile,DataModel)
main.php:177
ERROR [Warning]: stream_get_contents() expects parameter 1 to be resource, boolean given
IN GET /admin/pages/edit/EditorToolbar/viewfile?ID=92
Line 285 in /Users/drye/Development/Crossroads/Milacron/SS-CMS/framework/api/RestfulService.php
Source
======
276: }
277:
278: // Set any custom options passed to the request() function
279: curl_setopt_array($ch, $curlOptions);
280:
281: // Run request
282: $body = curl_exec($ch);
283:
284: rewind($headerfd);
* 285: $headers = stream_get_contents($headerfd);
286: fclose($headerfd);
287:
288: $response = $this->extractResponse($ch, $headers, $body);
289: curl_close($ch);
290:
291: return $response;
Trace
=====
stream_get_contents()
RestfulService.php:285
RestfulService->curlRequest(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png,GET,,,Array)
RestfulService.php:195
RestfulService->request()
Oembed.php:107
Oembed::autodiscover_from_url(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png)
Oembed.php:147
Oembed::get_oembed_from_url(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png)
HtmlEditorField.php:928
HtmlEditorField_Embed->__construct(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png,CloudImage)
HtmlEditorField.php:516
HtmlEditorField_Toolbar->viewfile(SS_HTTPRequest)
RequestHandler.php:288
RequestHandler->handleAction(SS_HTTPRequest,viewfile)
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
RequestHandler.php:222
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel)
LeftAndMain.php:443
LeftAndMain->handleRequest(SS_HTTPRequest,DataModel)
AdminRootController.php:93
AdminRootController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:370
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:153
Director::direct(/admin/pages/edit/EditorToolbar/viewfile,DataModel)
main.php:177
ERROR [Warning]: fclose() expects parameter 1 to be resource, boolean given
IN GET /admin/pages/edit/EditorToolbar/viewfile?ID=92
Line 286 in /Users/drye/Development/Crossroads/Milacron/SS-CMS/framework/api/RestfulService.php
Source
======
277:
278: // Set any custom options passed to the request() function
279: curl_setopt_array($ch, $curlOptions);
280:
281: // Run request
282: $body = curl_exec($ch);
283:
284: rewind($headerfd);
285: $headers = stream_get_contents($headerfd);
* 286: fclose($headerfd);
287:
288: $response = $this->extractResponse($ch, $headers, $body);
289: curl_close($ch);
290:
291: return $response;
292: }
Trace
=====
fclose()
RestfulService.php:286
RestfulService->curlRequest(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png,GET,,,Array)
RestfulService.php:195
RestfulService->request()
Oembed.php:107
Oembed::autodiscover_from_url(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png)
Oembed.php:147
Oembed::get_oembed_from_url(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png)
HtmlEditorField.php:928
HtmlEditorField_Embed->__construct(https://s3.amazonaws.com/crds-cms-uploads/Screen-Shot-2014-11-21-at-3.15.24-AM.png,CloudImage)
HtmlEditorField.php:516
HtmlEditorField_Toolbar->viewfile(SS_HTTPRequest)
RequestHandler.php:288
RequestHandler->handleAction(SS_HTTPRequest,viewfile)
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
RequestHandler.php:222
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel)
LeftAndMain.php:443
LeftAndMain->handleRequest(SS_HTTPRequest,DataModel)
AdminRootController.php:93
AdminRootController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:370
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:153
Director::direct(/admin/pages/edit/EditorToolbar/viewfile,DataModel)
main.php:177
When there is an upload error due to network issue or abrupt termination of upload (incomplete/corrupted image), it causes a read error and my app returns a internal server error.
CloudImage->getDimensions() probably should just return a 0x0 dimensions in this case
getimagesize(/Volumes/MainStorage/Development/Projects/htdocs/mmyapp/assets/Uploads/Member/45678/Items/14559942-240C-4542-8C2F-54A5F3DC699C-2.png) Image.php:1009 Image->getDimensions(string) CloudImage.php:87 CloudImage->getDimensions(0) Image.php:1022 Image->getWidth() Image.php:705 Image->isWidth(1200) Image.php:377 Image->ScaleWidth(1200) Image.php:526 Image->SetWidth(1200) ViewableData.php:466 ViewableData->obj(SetWidth,Array,1,,) SSViewer.php:99 SSViewer_Scope->getObj(SetWidth,Array,1,,) SSViewer.php:625 SSViewer_DataPresenter->getObj(SetWidth,Array,1,,) SSViewer.php:119 SSViewer_Scope->obj(SetWidth,Array,1,,) SSViewer.php:619
This would be optional, but would prevent long delays after upload and would allow larger files to be handled more safely.
...so it's better utilised in redundant environments.
This is a low priority task but needs to be done at some point. That logic is difficult to understand and therefore at greater risk of bugs being introduced.
edlinklater/silverstripe-cloudassets-s3 is now abandoned and silverstripe/s3 has replaced it. Can we get this updated?
Images are being processed as "from the web" so users see the hotlink warning and there is a bug in SS that doesn't respect the height and width set on images "from the web" I have a fix for the later, but it seems to me that this shouldn't be happening. This also seems to mean that the _resampled isn't really being used.
CloudAssetsTest::testMetadataRestoredOnCachedImageIfNotPresent
getimagesize(): Read error!
getimagesize(/Users/guinns/Dropbox/Sites/daywind/assets/FileTest-folder1/_resampled/SetWidth10-test-png32.png)
GD.php:456
GDBackend->writeTo(/Users/guinns/Dropbox/Sites/daywind/assets/FileTest-folder1/_resampled/SetWidth10-test-png32.png)
Image.php:475
call_user_func_array(Array,Array)
CloudImage.php:102
CloudImage->getFormattedImage(SetWidth,10)
Image.php:249
Image->SetWidth(10)
CloudAssetsTest.php:214
At this stage, error handling is largely silent such that if there's an upload or download error it just serves from the local assets as much as possible.
I'd like to see this taken up a notch:
Right now it just gives a big nasty 404 exception.
It should create the full path locally if needed.
You should be able to give an array of CDN urls and have it pick one randomly or round-robin each time Link() is called. This would allow you to set up multiple CNAME records to the CDN and utilise parallel connections better.
Something like:
BaseURL:
- http://media1.mysite.com
- http://media2.mysite.com
SecureURL:
- https://media3.mysite.com
- https://media4.mysite.com
This would give MUCH wider compatibility.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.