PHPackages                             webbycrown/s3-extension-for-bagisto - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. webbycrown/s3-extension-for-bagisto

ActiveLibrary

webbycrown/s3-extension-for-bagisto
===================================

S3 Extension for Bagisto

1.0.0(6mo ago)41604MITPHPPHP ^8.1

Since Nov 14Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/webbycrown/s3-extension-for-bagisto)[ Packagist](https://packagist.org/packages/webbycrown/s3-extension-for-bagisto)[ RSS](/packages/webbycrown-s3-extension-for-bagisto/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

WebbyCrown S3 Extension for Bagisto
===================================

[](#webbycrown-s3-extension-for-bagisto)

1. Introduction:
----------------

[](#1-introduction)

"S3 Extension for Bagisto" seamlessly integrates with Amazon S3, empowering store admins to effortlessly upload downloadable products, media files, product content, and images from their local disk to the S3 server. This free extension enables users to store and retrieve static files and media content directly from the S3 bucket, with added functionality to set expiration headers for enhanced control.

### Features:

[](#features)

- Compatible with all product types in Bagisto.
- Bucket manages the storage and retrieval of media files across various product categories, including product images, media within product descriptions, editing images, and more.
- Effortlessly store and retrieve files directly from the Amazon S3 Server.
- Customers can conveniently access and download files from the Amazon Server at any time and from any location.
- Cache images are now served directly from the Amazon S3 Server.
- Users have the option to save static files on the Amazon S3 server.
- The module offers versatile settings for configuring preferences.
- The extension allows setting expires headers for cached files, enhancing control over caching mechanisms.

2. Requirements:
----------------

[](#2-requirements)

- **PHP**: 8.0 or higher.
- **Bagisto**: v2.0.\*
- **Composer**: 1.6.5 or higher.

3. Installation:
----------------

[](#3-installation)

- Install the package below.

```
composer require webbycrown/s3-extension-for-bagisto

```

- Go to your Admin panel -&gt; click **configure** menu -&gt; click **Aws S3 Bucket** and full fill your bucket details.
- Go to the **config/filesystems.php** and add the following code.

```
's3' => [
  'driver' => 's3',
  'key' => env('AWS_ACCESS_KEY_ID'),
  'secret' => env('AWS_SECRET_ACCESS_KEY'),
  'region' => env('AWS_DEFAULT_REGION'),
  'bucket' => env('AWS_BUCKET'),
  'url' => env('AWS_URL'),
  'endpoint' => env('AWS_ENDPOINT'),
  'use_path_style_endpoint' =>env('AWS_USE_PATH_STYLE_ENDPOINT', false),
],
```

- Go to the **config/imagecache.php** file and replace the following line under **‘paths’**.

```
'paths' => [
        storage_path('app/public'),
        public_path('storage'),
    ],
```

Replace to

```
'paths' => [
        env('AWS_FILE_PATH'),
    ],
```

***Note:*** imagecache.php file does not exists than install [ImageCache](https://github.com/intervention/imagecache) library.

```
composer dump-autoload

```

```
php artisan optimize:clear

```

4. Configuration:
-----------------

[](#4-configuration)

### Admin Panel Settings

[](#admin-panel-settings)

Navigate to: **Admin Panel → Configuration → AWS → S3 Bucket**

Configure the following fields:

FieldDescriptionExample**Access Key**AWS IAM Access Key ID`AKIAIOSFODNN7EXAMPLE`**Secret Key**AWS IAM Secret Access Key`wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY`**Default Region**AWS Region where bucket exists`us-east-1`**Bucket Name**S3 Bucket name`my-bagisto-store`**Console URL**AWS S3 Console URL`https://s3.console.aws.amazon.com/...`**AWS URL**Public CDN/S3 URL for file access`https://my-bucket.s3.amazonaws.com` or `https://cdn.mystore.com`> **Note:** The extension automatically updates your `.env` file when you save these settings.

### What is AWS\_FILE\_PATH?

[](#what-is-aws_file_path)

`AWS_FILE_PATH` is the **public URL** where your S3 files are accessible. Examples:

```
# Direct S3 URL
AWS_FILE_PATH=https://my-bucket.s3.amazonaws.com

# S3 with region
AWS_FILE_PATH=https://my-bucket.s3.us-east-1.amazonaws.com

# CloudFront CDN (recommended)
AWS_FILE_PATH=https://d1234567890.cloudfront.net
```

5. Usage:
---------

[](#5-usage)

### Basic Upload/Delete Operations

[](#basic-uploaddelete-operations)

Apply this code wherever you want to upload or delete files to AWS S3:

```
// Upload Example
$s3Data = [
    'action' => 'upload',
    'imageUrl' => storage_path('app/public/product/images/sample.jpg'),
    'location' => 'product/images'  // Optional: S3 folder structure
];

$result = app('Webbycrown\S3Extension\S3Extension')->awsS3Operation($s3Data);

// Response:
// [
//     'imageName' => 'sample.jpg',
//     'imageUrl' => 'https://my-bucket.s3.amazonaws.com/product/images/sample.jpg',
//     'message' => 'Image Saved Successfully',
//     'status' => 'success',
//     'action' => 'upload',
//     'extension' => 'yes'
// ]
```

```
// Delete Example
$s3Data = [
    'action' => 'delete',
    'imageUrl' => storage_path('app/public/product/images/sample.jpg'),
    'location' => 'product/images'
];

$result = app('Webbycrown\S3Extension\S3Extension')->awsS3Operation($s3Data);
```

### Parameters

[](#parameters)

- **$action** : `upload` or `delete`
- **$imageUrl** : Full local file path (e.g., `storage_path('app/public/...')`)
- **$location** : S3 folder hierarchy (optional, e.g., `product/images`, `category/banners`)

### Get Uploaded S3 File URL

[](#get-uploaded-s3-file-url)

```
// If you stored the full URL in database
$imageUrl = $product->image; // https://my-bucket.s3.amazonaws.com/product/images/sample.jpg

// Or construct from path
$s3Url = env('AWS_FILE_PATH') . '/' . $path;
```

6. Advanced Usage:
------------------

[](#6-advanced-usage)

### Migrating Existing Images to S3

[](#migrating-existing-images-to-s3)

If you have existing images and want to migrate them to S3, create a custom command:

```
