Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
shvc committed Apr 18, 2022
1 parent 4001467 commit 7a70e8f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## s3java
s3java is [s3cli](https://github.com/shvc/s3cli) java edition.
[ref](https://github.com/awsdocs/aws-doc-sdk-examples)
s3java is [s3cli](https://github.com/shvc/s3cli) java edition.
Inspired by [awssdk](https://github.com/awsdocs/aws-doc-sdk-examples)

#### Download prebuild binary
https://github.com/shvc/s3java/releases
Expand All @@ -10,7 +10,7 @@ https://github.com/shvc/s3java/releases
gradle jar
```

## Example
## Usage
#### Bucket
```shell
# create Bucket
Expand All @@ -30,36 +30,38 @@ java -jar s3java-1.1.jar -e http://192.168.56.3:9000 -a root -s ChangeMe delete
- upload(put) Objcet(s)
```shell
# upload file(s)
java -jar s3java-1.1.jar upload bucket-name/k2 /etc/hosts # upload a file and specify Key(k2)
java -jar s3java-1.1.jar upload bucket-name/k2 /etc/hosts --v2sign # upload(V2 sign) a file and specify Key(k2)
java -jar s3java-1.1.jar upload bucket-name/k1 /etc/hosts # upload a file and specify Key(k1)
java -jar s3java-1.1.jar --v2sign upload bucket-name/k2 /etc/hosts # upload(V2 sign) a file and specify Key(k2)
java -jar s3java-1.1.jar upload bucket-name /etc/hosts # upload a file and use filename(hosts) as Key
java -jar s3java-1.1.jar upload bucket-name *.txt # upload files and use filename as Key
java -jar s3java-1.1.jar upload bucket-name/dir/ *.txt # upload files and set Prefix(dir/) to all uploaded Object
java -jar s3java-1.1.jar --presign put bucket-name/key3 # presign(V4) a PUT Object URL
java -jar s3java-1.1.jar --presign --v2sign put bucket-name/key3 # presign(V2) a PUT Object URL
java -jar s3java-1.1.jar --presign put bucket-name/k3 file # presign(V4) a PUT Object URL
java -jar s3java-1.1.jar --presign --v2sign put bucket-name/k4 file # presign(V2) a PUT Object URL
```
- download(get) Object(s)
```shell
# download Object(s)
java -jar s3java-1.1.jar download bucket-name/k1 # download Object(k1) to current dir
java -jar s3java-1.1.jar download bucket-name/k1 # download(V2 sign) Object(k1) to current dir
java -jar s3java-1.1.jar download bucket-name/k1 k2 k3 # download Objects(key, key1 and key2) to current dir
java -jar s3java-1.1.jar --v2sign download bucket-name/k2 # download(V2 sign) Object(k2) to current dir
java -jar s3java-1.1.jar download bucket-name/k1 k2 k3 # download Objects(k1, k2 and k3) to current dir
java -jar s3java-1.1.jar --presign download bucket-name/k1 # presign(V4) a GET Object URL
java -jar s3java-1.1.jar --presign --v2sign download bucket-name/k1 # presign(V2) a GET Object URL
java -jar s3java-1.1.jar --presign --v2sign download bucket-name/k2 # presign(V2) a GET Object URL
```

- list(ls) Objects
```shell
# list Objects
java -jar s3java-1.1.jar list bucket-name # list
java -jar s3java-1.1.jar list bucket-name/prefix # list Objects with specified prefix
java -jar s3java-1.1.jar list-v2 bucket-name # listObjects v2
java -jar s3java-1.1.jar list-v2 bucket-name/prefix # listObjects v2 with specified prefix
```

- delete(rm) Object(s)
```shell
# delete Object(s)
java -jar s3java-1.1.jar delete bucket-name/key # delete an Object
java -jar s3java-1.1.jar delete bucket-name/key1 key2 key3 # delete Objects
java -jar s3java-1.1.jar --presign delete bucket-name/k1 # presign(V4) an DELETE Object URL
java -jar s3java-1.1.jar --presign --v2sign delete bucket-name/k2 # presign(V2) an DELETE Object URL
java -jar s3java-1.1.jar delete bucket-name/k1 # delete an Object
java -jar s3java-1.1.jar delete bucket-name/k1 k2 k3 # delete Objects
java -jar s3java-1.1.jar --presign delete bucket-name/hosts # presign(V4) an DELETE Object URL
java -jar s3java-1.1.jar --presign --v2sign delete bucket-name/k4 # presign(V2) an DELETE Object URL
```
8 changes: 5 additions & 3 deletions src/main/java/org/shvc/s3java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Main implements Runnable {

@Option(names = {
"--presign-exp" }, showDefaultValue = CommandLine.Help.Visibility.ALWAYS, description = "presign Request expiration duration in minutes")
private long presignExp = 24*60;
private long presignExp = 24 * 60;

@Option(names = {
"--v2sign" }, showDefaultValue = CommandLine.Help.Visibility.ALWAYS, description = "S3 Client signature v2")
Expand Down Expand Up @@ -260,8 +260,10 @@ void delete(
cli.deleteBucket(bucket);
} else {
cli.deleteObject(bucket, key);
for (String k : keys) {
cli.deleteObject(bucket, k);
if (keys != null) {
for (String k : keys) {
cli.deleteObject(bucket, k);
}
}
}
}
Expand Down

0 comments on commit 7a70e8f

Please sign in to comment.