Storing images, etc. on Amazon S3

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
swpierce
Posts: 53
Joined: 01 Nov 2015, 13:19

Storing images, etc. on Amazon S3

Post by swpierce » 24 Nov 2015, 14:23

We're going to be storing our product images on Amazon S3. Just wanted to make sure that I don't need to do anything specific for Aimeos to work with S3. All I need to do is configure the Laravel filesystem provider and all will be well?

Thanks!

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Storing images, etc. on Amazon S3

Post by aimeos » 24 Nov 2015, 17:45

Almost :-)

You have to tell Aimeos to use your Amazon S3 URL as base URL:
https://aimeos.org/docs/Laravel/Optimiz ... atic_files
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

swpierce
Posts: 53
Joined: 01 Nov 2015, 13:19

Re: Storing images, etc. on Amazon S3

Post by swpierce » 24 Nov 2015, 22:59

Almost! :D

Missing one part.

When someone is creating a product via the admin interface and needs to upload an image for that product, we want the image to get stored in the S3 bucket - not in the uploads directory.

Pulling images from S3 is simple enough - just put the full URL in the mshop_media file. Works great.

my filesystem.php has:

Code: Select all

    's3' => [
            'driver' => 's3',
            'key'    => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],
my .env file is set up correctly with the above settings.

my config/shop.php includes:

Code: Select all

			'common' => array(
				'content' => array(
					'baseurl' => 'https://s3-us-west-2.amazonaws.com/bucketname/',
				),
I'm guessing, looking at the AdminController in the aimeos-laravel tree, that since this line exists:

Code: Select all

'uploaddir' => \Config::get( 'shop::uploaddir' ),
that it won't be as easy as trying to find a Storage::disk('local') and replace it with a Storage::disk('s3')

Can you point me in the right direction to override the media upload behavior in the admin side such that I don't break anything critical? :P

Thanks!

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Storing images, etc. on Amazon S3

Post by aimeos » 25 Nov 2015, 11:15

swpierce wrote: Can you point me in the right direction to override the media upload behavior in the admin side such that I don't break anything critical? :P
OK, that's currently a weak part of Aimeos. Files uploaded by the ExtJS admin interface are stored only locally. To change that, you have to use the Flysystem calls in https://github.com/aimeos/aimeos-core/b ... andard.php.

That's an improvement we need to add to the Aimeos Core. Are you able to open a pull request on Github with the necessary changes?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

swpierce
Posts: 53
Joined: 01 Nov 2015, 13:19

Re: Storing images, etc. on Amazon S3

Post by swpierce » 25 Nov 2015, 12:46

I'll work on that this weekend and see what I can do :)

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Storing images, etc. on Amazon S3

Post by aimeos » 27 Nov 2015, 14:57

We created a thin file system layer modeled after POSIX/Flysystem in the development version:
https://github.com/aimeos/aimeos-core/t ... Filesystem

The integration into the Laravel package is completed too, so it's possible now to use that file system layer to store and retrieve files from every supported (cloud) storage within the Aimeos library. It will use the configured default storage from the Laravel applications.

BTW: It's better to store only the relative paths in the media items because all paths in the storage are also relative. Furthermore, it's a lot easier to switch to a different cloud service if you only have to change the configuration (https://aimeos.org/docs/Configuration/C ... nt/baseurl)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

swpierce
Posts: 53
Joined: 01 Nov 2015, 13:19

Re: Storing images, etc. on Amazon S3

Post by swpierce » 27 Nov 2015, 19:25

Awesome! I'll pull it down and see if I can get it working.

Thanks!!

Post Reply