{"action":"created","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/1326","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/1326/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/1326/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/1326/events","html_url":"https://github.com/magento/magento2/issues/1326","id":83065001,"number":1326,"title":"Plan for media storage API?","user":{"login":"owenhaynes","id":1472893,"avatar_url":"https://avatars.githubusercontent.com/u/1472893?v=3","gravatar_id":"","url":"https://api.github.com/users/owenhaynes","html_url":"https://github.com/owenhaynes","followers_url":"https://api.github.com/users/owenhaynes/followers","following_url":"https://api.github.com/users/owenhaynes/following{/other_user}","gists_url":"https://api.github.com/users/owenhaynes/gists{/gist_id}","starred_url":"https://api.github.com/users/owenhaynes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owenhaynes/subscriptions","organizations_url":"https://api.github.com/users/owenhaynes/orgs","repos_url":"https://api.github.com/users/owenhaynes/repos","events_url":"https://api.github.com/users/owenhaynes/events{/privacy}","received_events_url":"https://api.github.com/users/owenhaynes/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/magento/magento2/labels/feature%20request","name":"feature request","color":"006b75"},{"url":"https://api.github.com/repos/magento/magento2/labels/PROD","name":"PROD","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-05-31T11:13:22Z","updated_at":"2016-02-14T12:53:23Z","closed_at":null,"body":"Is there any plan for a media stroage api, was looking to see if it was possible to use S3/Cloud Stroage for media assets. So that Elastic Beanstalk can be used effectively.\r\n\r\nI don't think storing the images in the database is the correct option when S3 storage is far cheaper and faster to run then a database. \r\n\r\nHave had a look at the code and it seems very tightly coupled with File and Database, so creating a plugin seems a lot of work."},"comment":{"url":"https://api.github.com/repos/magento/magento2/issues/comments/183883473","html_url":"https://github.com/magento/magento2/issues/1326#issuecomment-183883473","issue_url":"https://api.github.com/repos/magento/magento2/issues/1326","id":183883473,"user":{"login":"jameshalsall","id":499932,"avatar_url":"https://avatars.githubusercontent.com/u/499932?v=3","gravatar_id":"","url":"https://api.github.com/users/jameshalsall","html_url":"https://github.com/jameshalsall","followers_url":"https://api.github.com/users/jameshalsall/followers","following_url":"https://api.github.com/users/jameshalsall/following{/other_user}","gists_url":"https://api.github.com/users/jameshalsall/gists{/gist_id}","starred_url":"https://api.github.com/users/jameshalsall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jameshalsall/subscriptions","organizations_url":"https://api.github.com/users/jameshalsall/orgs","repos_url":"https://api.github.com/users/jameshalsall/repos","events_url":"https://api.github.com/users/jameshalsall/events{/privacy}","received_events_url":"https://api.github.com/users/jameshalsall/received_events","type":"User","site_admin":false},"created_at":"2016-02-14T12:53:23Z","updated_at":"2016-02-14T12:53:23Z","body":"@alankent @mazhalai \r\n\r\nWhilst I think this is \"achievable\" with a 3rd party module through the combination of plugin code and completely extending core Magento classes and replacing them through DI, I don't think this is a good solution. Currently the `Magento\\MediaStorage\\Helper\\File\\Storage\\Database` class does not implement any interface meaning that it's difficult to know exactly what needs to be implemented in a custom storage layer.\r\n\r\nI'm not even sure why it's referred to as database storage when all of the files reside on disk, not in the database. The only information stored in the database are the asset paths relative to the media path, and this would continue to be the case if we swapped it out for cloud storage alternatives. So \"Database\" is a poor name for this class.\r\n\r\nTo allow a bespoke storage layer we will need interfaces creating that will allow us to define logic for\r\n- creation of assets \r\n- deletion of assets\r\n- modification of assets\r\n- listing of assets\r\n\r\nEverything in `Magento\\MediaStorage\\Helper\\File\\Storage\\Database` only handles the management of assets, not the fetching of them. To customise behaviour of fetching assets, I can see a couple of places  that would need to be refactored for images (although I could be wrong so please correct me) but haven't found anything on generic file assets on my travels through M2 yet:\r\n- `\\Magento\\Catalog\\Block\\Product\\ImageBuilder::create()`\r\n- `\\Magento\\Catalog\\Helper\\Image::getUrl()`\r\n\r\nAgain there needs to be a clear set of interfaces defined that handle the fetching of assets which would allow us to customise this behaviour. The workflow I was hoping to easily implement in a module would be:\r\n\r\n1. Check if asset exists locally\r\n2. If not, fetch it from storage bucket e.g. S3\r\n3. Cache asset locally\r\n4. Return local URL for asset\r\n\r\n@alankent Your suggestion of just using a CDN doesn't really make sense, how is a Magento2 store currently meant to scale horizontally if all of the assets reside on phyiscal disk? The only easy solutions I can see right now are:\r\n- s3:// stream wrappers which makes for an extremely slow store\r\n- shared disk services like gluster or EFS (which still are not ideal)\r\n\r\nPlease let me know if I'm missing something obvious here.\r\n\r\nI look forward to hearing your thoughts"}}