-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No option to upload directory #529
Comments
Could you expand on the use case? |
Hi @ianmjones , global $as3cf;
$s3_config = new stdClass();
$s3_config->client = $as3cf->get_provider_client( $s3_region, true );
$s3_config->s3_bucket = $s3_bucket;
$s3_config->scheme = $as3cf->get_url_scheme();
$s3_config->domain = $as3cf->get_provider()->get_url_domain( $s3_config->s3_bucket, '', null, array(), true );
$s3_config->endpoint = trailingslashit( $s3_config->scheme . '://' . $s3_config->domain );
// listing objects
$s3_client = $s3_config->client;
$list_objects = $s3_client->list_objects(
array(
'Bucket' => $s3_bucket,
'Prefix' => 'wp-content/uploads/id123',
)
);
if ( is_array( $list_objects ) && ! empty( $list_objects['Contents'] ) ) {
$keys = $list_objects['Contents'];
$keys_mapped = array_map(
function ( $key ) {
return array(
'Key' => $key['Key'],
);
},
$keys
);
// check if the keys exist before trying to delete the files.
if ( ! empty( $keys ) ) {
// Delete the objects from s3.
$result = $s3_client->delete_objects(
array(
'Bucket' => $s3_bucket,
'Objects' => $keys_mapped,
)
);
}
}
// Uploading individual file - this works
$full_path = __DIR__ . '/uploads/file.jpg';
$s3_upload_args = array(
'Bucket' => $s3_bucket,
'Key' => 'wp-content/uploads/id123',
'SourceFile' => $full_path,
'ACL' => 'public-read',
));
);
$s3_client->upload_object( $s3_upload_args );
// Uploading directory --- NOT WORKING
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\S3\S3Client;
$source_path = __DIR__ . '/uploads/';
$upload_path = 'wp-content/uploads/directory';
$s3_upload_options = array(
'params' => array(
'ACL' => 'public-read',
),
);
// I couldn't use as3cf global object because it doesn't have upload directory method.
// instead I had to use S3Client directly. But it is not using the ACL as public-read
// it throws permission issue when I access it through public url.
$s3 = new S3Client(
array(
'version' => 'latest',
'region' => 'us-east-1',
)
);
$s3->uploadDirectory( $source_path, $s3_config->s3_bucket, $upload_path, $s3_upload_options ); It will be great to include upload directory option in the libraries. You are using own namespace to the library files. because of that, I couldn't get those thing works. |
Ok, so you're basically wanting a way to upload to S3 a bunch of files from a directory that aren't in the Media Library, correct? If so, isn't this a duplicate of #7 ? WP Offload Media currently only supports offloading and rewriting URLs for Media Library items, but we do plan to support offloading local media that isn't registered in the Media Library. We also plan to have a proper API that allows third party developers get info about an offloaded item, whether that be a Media Library item or not. At the moment there's a single as3cf_get_secure_attachment_url function available, but we're going to slowly start expanding that, with what is yet to be decided. But it should be emphasized that WP Offload Media is not a successor to the Amazon Web Services plugin, that was a general purpose wrapper around the AWS PHP SDK, but WP Offload Media most definitely is not. |
@ianmjones , |
Closing as a duplicate of #7 as uploading a directory of media that isn't in the Media Library amount to the same thing as handling files outside of the Media Library. We'll keep this use-case in mind though. |
there is no option to use your plugin to uploadDirectory by using as3cf global object. It will be nice to include UploadDirectory option or if we can get use of S3Client object
wp-amazon-s3-and-cloudfront/classes/providers/aws-provider.php
The text was updated successfully, but these errors were encountered: