Take a look at the as3cf_object_meta filter.
https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront-tweaks/blob/master/amazon-s3-and-cloudfront-tweaks.php#L138
The defaults are as follows:
$args = array(
'Bucket' => $bucket,
'Key' => $prefix . $file_name,
'SourceFile' => $file_path,
'ACL' => $acl,
'ContentType' => $type,
'CacheControl' => 'max-age=31536000',
'Expires' => date( 'D, d M Y H:i:s O', time() + 31536000 ),
);
You will need to modify the Key argument for a custom upload location.
Thanks for your reply. I tried the following, but it didn’t work. It still uploads to the root. In fact, it seems to ignore the code altogether. I tried replacing ‘wp/’ with gibberish, but the path didn’t change after I uploaded a file.
add_filter('as3cf_object_meta', 'as3cf_update_meta', 10, 2);
function as3cf_update_meta($args, $post_id)
{
$guid = get_the_guid($post_id);
$guid = str_replace('http://' . $_SERVER['HTTP_HOST'] . '/wp/wp-content/uploads/', '', $guid);
$args['Key'] = 'wp/' . $guid;
return $args;
}
Sorry I only gave you half the steps in the previous response. The filter provided should upload the file to the correct location on S3 (visible by using the AWS console). However, you also need to inform WordPress of the different location. To do this you need to filter the values before they’re added to the postmeta table. Try the sanitize_post_meta_amazonS3_info hook.
Thanks for the reply. I actually figured this out the other day. For the benefit of anyone else trying to do the same thing, here’s the code I used. In my add_attachment hook, I added the following:
add_action('as3cf_setting_object-prefix', 'setS3Path_' . $fcategory2, 10, 1);
$fcategory2 is my attachment category, which is what I’m using to determine which folder to put the file in. The function setS3Path_X looks something like this…
function setS3Path_audio($value)
{
return 'wp/audio';
}
function setS3Path_video($value)
{
return 'wp/video';
}
…with audio and video being different attachment categories.