humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.95k stars 392 forks source link

How to store the uploaded images in subfolders organized by YEAR/MONTH/DAY? #590

Closed abazeed closed 2 years ago

abazeed commented 2 years ago

Currently, all the uploaded images are stored directly in /uploads/ folder on the S3 bucket. Is there any way to store them in subfolders /yyyy/mm/dd/ automatically, and without the parent /uploads/ folder?

rmccue commented 2 years ago

Is there any way to store them in subfolders /yyyy/mm/dd/ automatically

This is a WordPress setting; see Settings > Media > Organize my uploads into month- and year-based folders

and without the parent /uploads/ folder

This can be achieved by filtering the upload directory after S3 Uploads has taken place.

Please also note our support policy :)

abazeed commented 2 years ago

This is a WordPress setting; see Settings > Media > Organize my uploads into month- and year-based folders

This will not add a day subfolder, it's only YYYY/MM, not YYYY/MM/DD.

I was able to resolve this using this hook s3_uploads_putObject_params of your plugin, like this:

function filter_s3_upload_path( array $params ): array {
    $params['Key'] = date('Y/m/d/') . basename( $params['Key'] );
    return $params;
}
add_filter( 's3_uploads_putObject_params', 'filter_s3_upload_path');