Uploading Media Files to Amazon S3 server
Last updated
Last updated
To Install Amazon Library, run this command
composer require aws/aws-sdk-php
To sync all your product image media files, category image media files, CMS page media files, and CMS block media files to the Amazon S3 server you must have to follow the below steps.
Note: Before using Amazon S3 cloud storage, take a backup of all the media files.
1. First, enable the extension from the back end and set up your Amazon S3 credential details. Run all the commands to your Magento Root Path.
2. Run the below command to upload your existing media files, such as images, catalog, products, etc., to the Amazon server.
php bin/magento amazons3:export
Note – Before running the export command, make sure you have a backup of all the media files. If the “Remove Media Directory Image Permanently” field is set to “Yes” in the backend configuration and you run the export command, then all the media files will be removed from the local server and exported to the Amazon server. Afterward, there is no option to recover media files on the local server.
First thing you need to do is to run export command before you run enable command to sync all existing media to S3. To use the export command, first, it would verify that you haven’t run enable command.
If you have already run enable command first, then you should run disable command first before running export command.
3. To enable S3 integration run below command
php bin/magento amazons3:enable
Once you run enable command than and only than you will be able to use our amazon S3 extension functionality, and using this command you need to set base media URL in system configuration (System->Configuration->General->Web-> Base URLs / Base URLs (Secure)) to access all the S3 media in system as per shown in below screenshot.
If you do not see any URL in base media field after running enable command, then you need to set that URL manually as per below screenshot.
Now if you create a new product it will be saved on local as well as S3 server by default. If you want to save new product only on S3 server run below command
sudo php bin/magento setup:config:set –remote-storage-driver=”aws-s3″ –remote-storage-bucket=”<Your Bucket name>” –remote-storage-region=”<Your Bucket Region name>” –remote-storage-key=<Your Bucket Access key> –remote-storage-secret=<Your Bucket Secret key>
If you again want the new product to be saved on local server, run below command
sudo php bin/magento setup:config:set –remote-storage-driver=”file”
4. To disable S3 integration run below command
php bin/magento amazons3:disable
If you do not want to use S3 media anymore, than you can run disable command. Using this command, S3 base media URL will be removed from system configuration. You can also remove the base media URL manually.
Once the upload is completed, you will be able to see all the product images in the Amazon S3 server as shown below.
You can also, see the before and after URL of images uploaded on the Amazon S3 server.