Skip to content
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

$client->uploadDirectory() always uploads every file, even when no changes #1959

Closed
curtiscarlson opened this issue Jan 24, 2020 · 12 comments
Closed
Assignees
Labels
feature-request A feature should be added or improved. p2 This is a standard priority issue

Comments

@curtiscarlson
Copy link

curtiscarlson commented Jan 24, 2020

Please fill out the sections below to help us address your issue.

Version of AWS SDK for PHP?

3.133.5

Version of PHP (php -v)?

PHP 7.2.21

What issue did you see?

when running uploadDirectory(), it creates a new version of every file in the folder

Steps to reproduce

If you have a runnable example, please include it as a snippet or link to a repository/gist for larger code examples.

No, just the basic function with a local source folder and a bucket destination, no other options or arguments

Additional context

Any additional information relevant to the issue. Examples include any framework you may be using (e.g. Laravel, Wordpress) in conjunction with the AWS SDK for PHP, or PHP/environment config settings if the issue is related to memory or performance.

windows / xampp

using slim/pimple and env, my setup looks like this

<?php

namespace App\Providers;

use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Aws\S3\S3Client;

class S3ServiceProvider implements ServiceProviderInterface
{
     public function register(Container $container) {

        // set up s3
        $container['s3client'] = function() {
            $client = new S3Client([
                'credentials' => [
                    'key'    => $_ENV['AWS_ACCESS_KEY_ID'],
                    'secret' => $_ENV['AWS_SECRET_ACCESS_KEY'],
                ],
                'region' => $_ENV['AWS_DEFAULT_REGION'],
                'version' => 'latest',
            ]);

            return $client;
        };

   }
}

Symfony console command:

<?php

namespace App\Commands;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use curtiscarlson\phplibs\ServiceLocator;

Class BackupStorage extends Command {

  protected function configure() {
    $this->setName('storage:backup')
      ->setDescription('Syncs the /storage folder to S3')
      ->setHelp('Syncs the /storage folder to S3');
  }

  public function execute(InputInterface $input, OutputInterface $output) {


      $client = ServiceLocator::get('s3client');

      $client->uploadDirectory(ROOT . '/storage', 'mybucketname');

  }

}
@curtiscarlson
Copy link
Author

could it be a permissions issue?

@curtiscarlson
Copy link
Author

To answer the question above, it is not a permissions issue. I added administrator rights to the user and the outcome is the same.

@diehlaws diehlaws self-assigned this Jan 27, 2020
@diehlaws diehlaws added the guidance Question that needs advice or information. label Jan 27, 2020
@diehlaws
Copy link
Contributor

Hi @curtiscarlson, thanks for reaching out to us. It sounds like you're expecting uploadDirectory() to behave in a manner similar to the s3 sync command in the AWS CLI; unfortunately the AWS SDK for PHP does not have a function similar to this CLI command.

Instead, uploadDirectory() intentionally uploads every file in the provided directory regardless of the contents of the destination prefix in the destination S3 Bucket. If you have versioning enabled on the bucket, this will result in new versions of existing objects being created when local files are re-uploaded to the bucket. Depending on your use case you could configure a lifecycle policy for the prefix to which your files are being re-uploaded in order to minimize the number of versions for these objects.

@diehlaws diehlaws added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 27, 2020
@curtiscarlson
Copy link
Author

curtiscarlson commented Jan 27, 2020

@diehlaws Thank you for your response. Are you sure though?

This page: https://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html states "The uploadDirectory() method of a client will compare the contents of the local directory to the contents in the Amazon S3 bucket and only transfer files that have changed. "

The page also explains that the function takes an options array, one of which is 'force', defined as "Set to true to upload every file, even if the file is already in Amazon S3 and has not changed." Which implies that the default is false. I have tried setting this option to false manually and it doesn't do anything.

Finally, the page explains that "The uploadDirectory() method is an abstraction layer over the much more powerful Aws\S3\Sync\UploadSyncBuilder". Which means to imply that it is indeed similar to the s3 sync command. (It is also all under the "Syncing data with Amazon S3" heading).

Thanks again.

@diehlaws diehlaws removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 28, 2020
@diehlaws
Copy link
Contributor

No problem! The documentation page you mentioned is for version 2 of the AWS SDK for PHP. It looks like this function was changed with the release of version 3 of the AWS SDK for PHP so that, instead of iterating through existing objects in the destination bucket/prefix to only copy new and changed files from the local directory, it copies the full contents of the given directory regardless of the contents of the destination. Unfortunately it does not look like a new function was ever created in V3 to implement the functionality present in the V2 S3Client's UploadDirectory() function.

That being said, you can provide an iterator to the S3 Transfer's constructor method to then call its transfer() function so that only new/changed files are transferred to the destination bucket. Alternately, if you'd like to see a sync function implemented in the S3 Client for V3 we can mark this as a feature request for future implementation - unfortunately we have a number of higher priority items at this time so implementation for this may be slow without external contributions.

@diehlaws diehlaws added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 28, 2020
@curtiscarlson
Copy link
Author

curtiscarlson commented Jan 28, 2020

@diehlaws I think both of your suggestions are probably over my head. I tried to find the V2 code on github but I would have to click for hours to get back that far. I want to say that I think this functionality is extremely important and that you should reconsider its priority, for the following reasons

  • There is no purpose whatsoever to uploading every file every time and making a new version in place (that I can see)
  • It's bad for the environment, bad for users bills, bad for internet traffic, and bad for site availability
  • It's already been documented to work this way

If you point me in the right direction to the original code I might be able to make the contribution but as I said I might be over my head. Thank you.

@diehlaws diehlaws added feature-request A feature should be added or improved. and removed guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jan 28, 2020
@diehlaws
Copy link
Contributor

Thanks for the feedack @curtiscarlson! I've marked the issue as a feature request and will bring it up with the rest of the team in the next team sprint.

You can review the code for V2 of the SDK by switching branches in this repo from master to 2.8. Please keep in mind that there are some pretty significant changes both to the core SDK and the S3 client between v2 and v3 of the AWS SDK for PHP, so simply porting the code for v2's uploadDirectory to a new function in v3 likely won't work as expected.

@diehlaws diehlaws removed their assignment Aug 26, 2020
@howardlopez howardlopez added the no-autoclose This issue should not be auto-closed by stale-issue-cleanup action. label Aug 27, 2020
@alexwai
Copy link

alexwai commented Jan 10, 2021

Any update on this issue

@curtiscarlson
Copy link
Author

@alexwai
I found a sync package on packagist and updated it to meet my needs.

@danielerne
Copy link

Very disappointed that this was removed in v3. We upload hundreds of files every 30 minutes.

@stobrien89 stobrien89 self-assigned this Mar 30, 2022
@yenfryherrerafeliz yenfryherrerafeliz added the p2 This is a standard priority issue label Jan 2, 2023
@stobrien89 stobrien89 removed the no-autoclose This issue should not be auto-closed by stale-issue-cleanup action. label Dec 6, 2023
@stobrien89
Copy link
Member

Hi all,

We've had a number of conversations about this as a team and we've decided that the PHP SDK will not be implementing this feature. At least until the SDKs have settled on a shared specification of a sync-like customization. Closing for now, but happy to answer any questions you might have.

Copy link

github-actions bot commented Dec 6, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

7 participants