In version 1.0.3 of SyncsS3 for Gravity Forms, we introduced a couple new filters that allow you to apply custom logic on bucket names and file paths. These filters include syncs3_put_object_bucket_name
, and syncs3_put_object_file_path
.
With these filters, you can create more complex logic for determining which buckets file uploads, thereby overriding the default that you set within SyncS3.
You can also set a custom file path for the files. By default, SyncS3 places files into a folder within your bucket that looks like form-{form_id}
, where form_id is the ID of your Gravity Form. The syncs3_put_object_file_path
lets you override that default, and create a nested folder structure for your files.
Customize the Amazon S3 Bucket Name in SyncS3
add_filter( 'syncs3_put_object_bucket_name', 'customize_syncs3_bucket_name', 10, 6 );
/**
* Custom logic to set the bucket name in SyncS3 for Gravity Forms
*
* @param string $bucket_name Bucket name
* @param string $file Local file URL when uploaded
* @param string $file_name Name of uploaded file
* @param int $field_id ID of the fileupload field
* @param int $form_id ID of the form
* @param array $entry Entry data
*
* @return string Bucket name
*/
function customize_syncs3_bucket_name( $bucket_name, $file, $file_name, $field_id, $form_id, $entry ) {
// Custom logic here
return $bucket_name;
}
Customize the Amazon S3 File Path in SyncS3
add_filter( 'syncs3_put_object_file_path', 'customize_syncs3_path', 10, 6 );
/**
* Custom logic to set the bucket name in SyncS3 for Gravity Forms
*
* @param string $path File path to return. Make sure the path ends with $file_name.
* @param string $file Local file URL when uploaded
* @param string $file_name Name of uploaded file
* @param int $field_id ID of the fileupload field
* @param int $form_id ID of the form
* @param array $entry Entry data
*
* @return string Bucket name
*/
function customize_syncs3_path( $path, $file, $file_name, $field_id, $form_id, $entry ) {
// Custom logic
$path = "testing/new/{$file_name}"; // Make sure the new path includes the file name
return $path;
}
These code snippets can be placed in a custom functions plugin, or your theme’s functions.php
file.