andersundsehr/aus-driver-amazon-s3 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

andersundsehr/aus-driver-amazon-s3

Composer 安装命令:

composer require andersundsehr/aus-driver-amazon-s3

包简介

Provides a FAL driver for the Amazon Web Service AWS S3.

README 文档

README

Packagist Release Packagist Downloads GitHub License Code Climate Contributors

TYPO3 Extension: Amazon AWS S3 FAL driver (CDN)

This is a driver for the file abstraction layer (FAL) to support Amazon AWS S3.

You can create a file storage which allows you to upload/download and link the files to an AWS S3 bucket. It also supports the TYPO3 CMS image rendering.

Requires TYPO3 11.5 - 12.4

Issue tracking: GitHub: AWS S3 FAL Driver

Packagist: andersundsehr/aus-driver-amazon-s3

Installation

  1. Install the TYPO3 extension via composer (recommended) or install the extension via TER (not recommended anymore).

Composer installation:

composer require andersundsehr/aus-driver-amazon-s3
  1. Add a new file storage with the “AWS S3” driver to root page (pid = 0).
  2. Configure your file storage

Configuration

Driver Configuration

Add the following configurations:

  • Bucket: The name of your AWS S3 bucket
  • Region: The region of your bucket (avoid dots in the bucket name)
  • Key and secret key of your AWS account (optional, you can also use IAM roles or environment variables)
  • Public base url (optional): this is the public url of your bucket, if empty its default to “bucketname.s3.amazonaws.com”
  • Protocol: network protocol (https://, http:// or auto detection)

Hint: Amazon AWS S3 bucket configuration

Make sure that your AWS S3 bucket is accessible to public web users.

For example add the following default permissions to “Edit bucket policy”:

Example permissions:

{
  "Version": "2008-10-17",
  "Statement": [
      {
          "Sid": "AddPerm",
          "Effect": "Allow",
          "Principal": "*",
          "Action": "s3:GetObject",
          "Resource": "arn:aws:s3:::bucketname/*"
      }
  ]
}

Extension Configuration

Edit in “Extension Manager” the following extension settings:

  • dnsPrefetch Use DNS prefetching tag: If enabled, an HTML tag will be included which prefetchs the DNS of the current CDN
  • enablePermissionsCheck Check S3 permissions for each file and folder. This is disabled by default because it is very slow (TYPO3 has to make an AWS request for each file)

Cache Configuration

Customizing TYPO3 Cache Backends

  • ausdriveramazons3_metainfocache retains metadata from AWS S3 on a per-object basis.
  • ausdriveramazons3_requestcache stores the complete response of a specific request, facilitating efficient data access and performance enhancement.

By default, these caches are transient. However, if you choose to configure a persistent cache backend, it's crucial to remember that such a cache will not automatically recognize changes from the data source. In this case, it becomes your responsibility to implement the necessary updates manually.

Detailed instructions on how to customize these cache backends can be found in the TYPO3 CachingFramework Configuration Guide. Remember, thorough testing is essential when modifying cache backends.

Example with simple file backend; all changes through TYPO3

[
    'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
    'backend' => \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class,
    'groups' => [
        'pages'
    ],
];

Example with redis

[
    'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
    'backend' => \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class,
    'options' => [
        'defaultLifetime' => 0, // infinite
        'database' => 0,
        'hostname' => 'redis',
        'port' => 6379,
    ],
];

Extend Extension

Initialize S3 Client

If you use your own Amazon AWS SDK, you may want to work with your own S3 client object.

So you have to use the following hook in your own ext_loaclconf.php:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aus_driver_amazon_s3']['initializeClient-preProcessing'][] = \Vendor\ExtensionName\Hooks\AmazonS3DriverHook::class . '->initializeClient';

A hook class might look like this:

namespace Vendor\ExtensionName\Hooks;

class AmazonS3DriverHook {

  public function initializeClient(array &$params, $obj){
    $params['s3Client'] = MyAwsFactory::getAwsS3Client($params['configuration']);
  }
}

Initialize public base URL

You can set the public base URL in the configuration of your driver (TYPO3 backend). But maybe you want to set this on an other place.

So you have to use the following hook in your own ext_loaclconf.php:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aus_driver_amazon_s3']['initializeBaseUrl-postProcessing'][] = \Vendor\ExtensionName\Hooks\AmazonS3DriverHook::class . '->initializeBaseUrl';

A hook class might look like this:

namespace Vendor\ExtensionName\Hooks;

class AmazonS3DriverHook {

  public function initializeBaseUrl(array &$params, $obj){
    $params['baseUrl'] = 'https://example.com';
  }
}

Cache Control Header

There is a default setting to set the cache control header's max age for all file types. If you want to use special cache headers, you can use this hook:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aus_driver_amazon_s3']['getCacheControl'][] = 'Vendor\ExtensionName\Hooks\AmazonS3DriverHook->getCacheControl';

You can modify the parameter "cacheControl" as you wish. Please Notice: AWS S3 set the cache header only once - while uploading / creating or copy the file.

More

If you wish other hooks - don’t be shy: GitHub issue tracking: Amazon S3 FAL Driver

Development

Running tests

Run make tests to run both unit and functional tests.

To switch TYPO3 test version to 11:

composer update --with typo3/cms-core:^11.5.6

To switch TYPO3 test version to 12:

composer update --with typo3/cms-core:^12.4.0 --ignore-platform-req=ext-intl

andersundsehr/aus-driver-amazon-s3 适用场景与选型建议

andersundsehr/aus-driver-amazon-s3 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 276.2k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2015 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 andersundsehr/aus-driver-amazon-s3 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 andersundsehr/aus-driver-amazon-s3 我们能提供哪些服务?
定制开发 / 二次开发

基于 andersundsehr/aus-driver-amazon-s3 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 276.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 25
  • 点击次数: 25
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 7
  • Forks: 49
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2015-11-16