Git Product home page Git Product logo

aws-s3-media-source's Introduction

Amazon S3 Media Source for MODX Revolution

Using 3.* https://aws.amazon.com/sdk-for-php/ & https://github.com/aws/aws-sdk-php

What are Media Sources? https://docs.modx.com/revolution/2.x/administering-your-site/media-sources

Features

  • CRUD (create, read, update and delete) for files and folders
  • Rename files and folders, #7
  • Move/Drag files and folders within the same Media Source, #7
  • Limit an S3 Media Source to sub directory/folder of a given Bucket. #5
  • Works with static sites with custom domains, example: assets.example.com

Set up

Download the latest release and install via Package Manager

  1. Then in the MODX Manager go to Media -> Media Sources -> Create New Media Source
  2. Fill in the Required options
  3. Save

aws-s3-media-source's People

Contributors

jgulledge19 avatar matdave avatar theboxer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-s3-media-source's Issues

Delete File/Folder, removeObject and removeConatainer Fails

S3 does not have folders or directories so the object name or key needs the trailing delimiter (/). See:

Files need only the Key which appears to be the relative path. So the URL property that MODX adds to the passed parameter needs to be removed.

References

Feature: Limit Media Source to sub directory/folder

Limit a S3 Media Source to sub directory/folder of a given Bucket. Similar to the ability to do so with the local filesystem which uses: basePath and baseUrl.

Why is this needed?
Take for example setting up S3 as a static site with custom domain like: assets.example.com. You want that URL on all assets so you don't want to create lots of different Buckets for each Media Source. It would be ideal to set several Media Sources to one Bucket and to have it be limited to a selected folder.

Reference
https://docs.modx.com/revolution/2.x/administering-your-site/media-sources/media-source-types/media-source-type-file-system

Thumbnails on s3 bucket not displaying

On MODX 2.8.3 with AWS S3 Media Source Extra installed thumbnails are not displaying for images of any size in the bucket. A small window does pop up displaying a 404 icon. So it makes the file but can't find it to display.

I have contacted MODX support about this. Here's what he last said:

The error is stating that bucket does not yet exist. By the looks of your code, the bucket name is not correct, which is why a file cannot be found.

<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
<BucketName>bmcm-aws</BucketName>

I have confirmed that the bucket name is correctly entered in Media Source.

Also, note that the BucketName in the above code is actually the S3 account name which only appears as part of the URL for the Amazon S3 instance in the Media Source setup.

Any ideas? . . .

Create Directory Here fails

Right click on a directory for your S3 media source and then click on Create Directory Here. The Parent Directory (pathRelative) is not set and by default will send to the root on save.

Rename File/Folder and Move Folder

Bug: rename a single file fails.

Features:

  • Rename Folder
  • Move (drag) Folder to new location within same media source. From an S3 point view move and rename are the same, copy file by file and then delete old.

PHP 8+ error in isBinary() method when trying to open a resource in the bucket that is not accessible

Found a problem on a MODX Cloud site today that was using PHP 8.1 related to binary resources and the resource in question not having the ACLs required to be accessed.

The problem is in core/components/awss3mediasource/model/awss3mediasource/awss3mediasource.class.php on line 341.

The error suppression on the fread no longer works in PHP 8+ and will cause a fatal PHP error that stops any of the resources loading in the Media Source view in the Manager when the file being processed returns false from the fopen - for example, a 403 Forbidden response.

My fix was to add an explicit check right after the fopen:

if ($fh == false) { return false;}

That way, processing continues and valid resources will still be able to be displayed.

Feature add Caching of Container Contents, listDirectory() method

The media source tree does lots of API calls to S3 and this can be resource intensive if you have several S3 media source with nested folders.

Use xPDOCacheManager to cache the what the directory and files are in the media source. When a file or folder is created, updated or deleted also clear the cache for the related tree.

Run a `composer update` and release an update

The AWS SDK version that ships in the released 1.0.0 version is really quite old, and not compatible with Guzzle 7 or up. This can cause version conflicts; usually those are resolved by installing the guzzle7 package which forcefully loads the relevant files to avoid that, however that doesn't work with this package currently.

The error thrown is:

( ! ) Fatal error: Uncaught Error: Undefined class constant 'VERSION' in core/components/awss3mediasource/model/vendor/aws/aws-sdk-php/src/functions.php on line 265

I manually ran composer update in the model folder and that resolved it without further steps.

Amazon S3 Media Source not in Package Manager

The README suggests that this package can be found and installed from Package Manager, but I'm not seeing it my package manager when I search for 'aws', 's3', 'media' or other derivations of the name of this package. (I'm on Revo 2.6.1)

Is this a package I should be able to find in Package Manager?

The reason I ask is that I'm not having any success with the built-in s3 bucket media source option in MODX, and I'm hoping this is not the same (updated or whatever).

Don't hard-code the S3 URL. If not hard-coded, it's also compatible with Digital Ocean Spaces

I have added 'endpoint' =>'https://sgp1.digitaloceanspaces.com'
into line 54 of model/aws3smediasource.class.php like this:

$this->driver = new Aws\S3\S3Client([
    'version' => 'latest',
    'endpoint'=> 'https://sgp1.digitaloceanspaces.com',
    'region' => $this->xpdo->getOption('region', $this->properties, ''),
    'credentials' => [
        'key' => $this->xpdo->getOption('key', $this->properties, ''),
        'secret' => $this->xpdo->getOption('secret_key', $this->properties, '')
    ]
]);

and now it works with Digital Ocean Spaces!
(of course you need to change the "sgp1" sub-domain to whatever you're using.)

getObjectContents() doesn't return file content for binary files

https://github.com/modxcms/aws-s3-media-source/blob/master/core/components/awss3mediasource/model/awss3mediasource/awss3mediasource.class.php#L1491

Example is when using this media source with MoreGallery; that will use getObjectContents() to load the image to create thumbnails/crops, however that wont work because images are binary files.

I'm not quite sure why the check on binary files is there to begin with, and have confirmed it works fine when replacing the ternary with just $contents.

Unable to view preview Thumbnails for images

I am using a bucket located at an academic institution's S3 instance. Running MODX 2.8.3 with aws-s3-media-source installed. I get the following errors in the manager error log when preview thumbnails are generated by hovering over image file name:

[2022-03-18 08:23:07] (ERROR @ /www/core/components/awss3mediasource/model/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php : 67) PHP warning: count(): Parameter must be an array or an object that implements Countable
[2022-03-18 08:23:08] (ERROR @ /www/core/components/awss3mediasource/model/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php : 67) PHP warning: count(): Parameter must be an array or an object that implements Countable

Additionally the same problem occurs in MODX 3 latest version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.