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

Amazon S3: Add option to download to and overwrite existing files #2595

Closed
wants to merge 1 commit into from

Conversation

mina-asham
Copy link

Motivation and Context

Issue: #2300

Migrating from SDK V1 to V2 we hit an issue where do something like this (pseudo-code):

Path temp = Files.createTempFile(...);
s3.getObject(bucket, key, temp);
// use temp file

This allows us to download a temp file, validate it and if we are happy flip it to the actual path overriding the existing previous file.

This works on V1 because: because it just opens an outputstream which by default overwrites (here)
but doesn't work on V2 because we are not passing any options to Files.copy (here)

Description

This adds the option to download to and overwrite existing files by adding another method overload for toFile with a boolean flag to overwrite which translate to calling Files.copy with StandardCopyOption.REPLACE_EXISTING option (only option allowed when using Files.copy with an input stream)

Testing

Added a unit test

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@mina-asham
Copy link
Author

I see that the changelog is auto-generated, so I haven't checked the CHANGELOG checkbox, but let me know if I missed something here.

@sonarcloud
Copy link

sonarcloud bot commented Jul 14, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@vedarths
Copy link

vedarths commented Feb 8, 2022

hello!

Please are there any updates on this issue?

Also attempting to download a file from S3 using the GetObjectRequest like below which also throws a FileAlreadyExistsException

val tempDirectory = createTempDirectory()

//client is an instance of S3Client

client.getObject(
                    GetObjectRequest
                            .builder()
                            .key(key)
                            .bucket(s3Configuration.bucket)
                            .build(),
                    tempDirectory))

this throws a FileAlreadyExistsException too

My Gradle dependency is as follows:

    implementation("software.amazon.awssdk:s3:$2.17.39")

@rzhang90
Copy link

hello!

Please are there any updates on this issue?

Also attempting to download a file from S3 using the GetObjectRequest like below which also throws a FileAlreadyExistsException

val tempDirectory = createTempDirectory()

//client is an instance of S3Client

client.getObject(
                    GetObjectRequest
                            .builder()
                            .key(key)
                            .bucket(s3Configuration.bucket)
                            .build(),
                    tempDirectory))

this throws a FileAlreadyExistsException too

My Gradle dependency is as follows:

    implementation("software.amazon.awssdk:s3:$2.17.39")

I got this error too.

@aegbert5
Copy link

aegbert5 commented Jun 27, 2022

Any updates on this issue? I've been getting the same error

@mina-asham
Copy link
Author

mina-asham commented Apr 17, 2023

I am closing this since we got zero responses from AWS team for a year and a half now, thanks folks!

@mina-asham mina-asham closed this Apr 17, 2023
@rsteilberg-foreflight
Copy link

Heads up, this appears to be resolved per this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants