aws / aws/aws-sdk-java-v2

S3: GetObjectRequest toFile option to override file

Aperta
#2,300 4 commenti 2 reazioni 0 assegnatari Vedi su GitHub
feature-request p1 service:s3
Lingua principale
Java
Stelle
2.6k
Fork
1k
Merge medio
2g 9h
PR unite (30g)
51

Descrizione

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](https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/internal/ServiceUtils.java#L304))
but doesn't work on V2 because we are not passing any options to `Files.copy` ([here](https://github.com/aws/aws-sdk-java-v2/blob/master/core/sdk-core/src/main/java/software/amazon/awssdk/core/sync/ResponseTransformer.java#L106))

## Describe the Feature

Allow the use of S3 client to download an object to an existing file by overwriting it

## Is your Feature Request related to a problem?

See general summary

## Proposed Solution

* Suggestion 1 (preferred): adding an overload with a boolean `overwrite` for this `toFile` method [here](https://github.com/aws/aws-sdk-java-v2/blob/master/core/sdk-core/src/main/java/software/amazon/awssdk/core/sync/ResponseTransformer.java#L102) that can be passed to the `Files.copy` call as `StandardCopyOption.REPLACE_EXISTING` (only option allowed when using `Files.copy` with an input stream)
* Suggestion 2 (less preferred because it's ugly but works): Add another method in `ResponseTransformer`, e.g. `ResponseTransformer.toFileOverwrite`
* Suggestion 3 (not preferred because it's a breaking change): Change the default behaviour and hardcode `StandardCopyOption.REPLACE_EXISTING`

## Describe alternatives you've considered

See suggestion 2/3 in proposed solution

## Additional Context

- [x] I may be able to implement this feature request

## Your Environment

* AWS Java SDK version used: N/A
* JDK version used: N/A
* Operating System and version: N/A

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start with core/sdk-core/src/main/java/software/amazon/awssdk/core/sync/ResponseTransformer.java and the Files.copy call identified in the issue. Review the existing toFile behavior and the proposed overwrite options. Done means an S3 download can target an existing file without failing, with the selected API behavior clearly defined.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, java
Ambito
api, cloud
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
52/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.