Skip to content

Commit 26787af

Browse files
sinhaashishkannappanr
authored andcommitted
Add overloaded methods for putObject API (#747)
1. public void putObject(String bucketName, String objectName, String fileName, Long size, Map<String,String> headerMap, ServerSideEncryption sse, String contentType) 2. public void putObject(String bucketName, String objectName, InputStream data, Long size, Map<String, String> headerMap, ServerSideEncryption sse, String contentType) These two methods can take values/null for all the optional parameters.
1 parent b2028f5 commit 26787af

20 files changed

+738
-216
lines changed

api/src/main/java/io/minio/MinioClient.java

Lines changed: 372 additions & 136 deletions
Large diffs are not rendered by default.

api/src/test/java/io/minio/MinioClientTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ public void testPutSmallObject()
559559
String inputString = HELLO_WORLD;
560560
ByteArrayInputStream data = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
561561

562-
client.putObject(BUCKET, "key", data, 11, APPLICATION_OCTET_STREAM);
562+
client.putObject(BUCKET, "key", data, 11L, null, null, APPLICATION_OCTET_STREAM);
563563
}
564564

565565
// this case only occurs for minio cloud storage
@@ -584,7 +584,7 @@ public void testPutSmallObjectFails()
584584
String inputString = HELLO_WORLD;
585585
ByteArrayInputStream data = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
586586

587-
client.putObject(BUCKET, "key", data, 11, APPLICATION_OCTET_STREAM);
587+
client.putObject(BUCKET, "key", data, 11L, null, null, APPLICATION_OCTET_STREAM);
588588
throw new RuntimeException(EXPECTED_EXCEPTION_DID_NOT_FIRE);
589589
}
590590

@@ -609,7 +609,7 @@ public void testPutIncompleteSmallPut()
609609
String inputString = "hello worl";
610610
ByteArrayInputStream data = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
611611

612-
client.putObject(BUCKET, "key", data, 11, APPLICATION_OCTET_STREAM);
612+
client.putObject(BUCKET, "key", data, 11L, null, null, APPLICATION_OCTET_STREAM);
613613
throw new RuntimeException(EXPECTED_EXCEPTION_DID_NOT_FIRE);
614614
}
615615

@@ -638,7 +638,7 @@ public void testSpecialCharsNameWorks()
638638
ascii[i - 1] = (byte) i;
639639
}
640640
String contentType = null;
641-
client.putObject(BUCKET, "世界" + new String(ascii, "UTF-8"), data, 11, contentType);
641+
client.putObject(BUCKET, "世界" + new String(ascii, "UTF-8"), data, 11L, null, null, contentType);
642642
}
643643

644644
@SuppressFBWarnings("NP")
@@ -662,7 +662,7 @@ public void testNullContentTypeWorks()
662662
ByteArrayInputStream data = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
663663

664664
String contentType = null;
665-
client.putObject(BUCKET, "key", data, 11, contentType);
665+
client.putObject(BUCKET, "key", data, 11L, null, null, contentType);
666666
}
667667

668668
@Test
@@ -684,7 +684,7 @@ public void testCustomContentTypeWorks()
684684
String inputString = HELLO_WORLD;
685685
ByteArrayInputStream data = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
686686

687-
client.putObject(BUCKET, "key", data, 11, APPLICATION_JAVASCRIPT);
687+
client.putObject(BUCKET, "key", data, 11L, null, null, APPLICATION_JAVASCRIPT);
688688
}
689689

690690
@Test
@@ -828,7 +828,7 @@ private RecordedRequest putObjectWithHeaders(Map<String, String> headerMap)
828828
server.start();
829829

830830
MinioClient client = new MinioClient(server.url("").toString(), "access_key", "secret_key", "us-east-1");
831-
client.putObject(BUCKET, "key", new ByteArrayInputStream(new byte[]{'a'}), 1, headerMap);
831+
client.putObject(BUCKET, "key", new ByteArrayInputStream(new byte[]{'a'}), 1L, headerMap, null, null);
832832

833833
return server.takeRequest();
834834
}

docs/API.md

Lines changed: 276 additions & 1 deletion
Large diffs are not rendered by default.

examples/CopyObject.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public static void main(String[] args)
6565
ByteArrayInputStream bais = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
6666

6767
// Create object 'my-objectname' in 'my-bucketname' with content from the input stream.
68-
minioClient.putObject("my-bucketname", "my-objectname", bais, bais.available(), "application/octet-stream");
68+
minioClient.putObject("my-bucketname", "my-objectname", bais, Long.valueOf(bais.available()), null, null,
69+
"application/octet-stream");
6970
bais.close();
7071
System.out.println("my-objectname is uploaded successfully");
7172

examples/CopyObjectEncrypted.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static void main(String[] args)
6161
ServerSideEncryption sseTarget = ServerSideEncryption.withCustomerKey(secretKeySpecTarget);
6262

6363
// Create object 'my-objectname' in 'my-bucketname' with content from the input stream.
64-
minioClient.putObject("my-bucketname", "my-objectname", bais, bais.available(), ssePut);
64+
minioClient.putObject("my-bucketname", "my-objectname", bais, Long.valueOf(bais.available()), null, ssePut, null);
6565
System.out.println("my-objectname is uploaded successfully");
6666

6767
minioClient.copyObject("my-bucketname", "my-objectname", sseSource, "my-destbucketname",
@@ -75,4 +75,4 @@ public static void main(String[] args)
7575
}
7676
System.out.println("finished");
7777
}
78-
}
78+
}

examples/CopyObjectEncryptedKms.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void main(String[] args)
5757
ServerSideEncryption sse = ServerSideEncryption.withManagedKeys("Key-Id", myContext);
5858

5959
// Create object 'my-objectname' in 'my-bucketname' with content from the input stream.
60-
minioClient.putObject("my-bucketname", "my-objectname", bais, bais.available(), sse);
60+
minioClient.putObject("my-bucketname", "my-objectname", bais, Long.valueOf(bais.available()), null, sse, null);
6161
bais.close();
6262
System.out.println("my-objectname is uploaded successfully");
6363

examples/CopyObjectEncryptedS3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void main(String[] args)
5151
ServerSideEncryption sse = ServerSideEncryption.atRest();
5252

5353
// Create object 'my-objectname' in 'my-bucketname' with content from the input stream.
54-
minioClient.putObject("my-bucketname", "my-objectname", bais, bais.available(), sse);
54+
minioClient.putObject("my-bucketname", "my-objectname", bais, Long.valueOf(bais.available()), null, sse, null);
5555
bais.close();
5656
System.out.println("my-objectname is uploaded successfully");
5757

examples/CopyObjectMetadata.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public static void main(String[] args)
6767
ByteArrayInputStream bais = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
6868

6969
// Create object 'my-objectname' in 'my-bucketname' with content from the input stream.
70-
minioClient.putObject("my-bucketname", "my-objectname", bais, bais.available(), "application/octet-stream");
70+
minioClient.putObject("my-bucketname", "my-objectname", bais, Long.valueOf(bais.available()),null, null,
71+
"application/octet-stream");
7172
bais.close();
7273
System.out.println("my-objectname is uploaded successfully");
7374

examples/PutGetObjectEncrypted.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static void main(String[] args)
6161
// To test SSE-C
6262
ServerSideEncryption sse = ServerSideEncryption.withCustomerKey(keyGen.generateKey());
6363

64-
minioClient.putObject("my-bucketname", "my-objectname", bais, bais.available(), sse);
64+
minioClient.putObject("my-bucketname", "my-objectname", bais, Long.valueOf(bais.available()),null, sse, null);
6565

6666
bais.close();
6767

examples/PutGetObjectEncryptedFile.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import java.security.NoSuchAlgorithmException;
44
import java.security.InvalidKeyException;
55

6+
67
import javax.crypto.KeyGenerator;
78
import org.xmlpull.v1.XmlPullParserException;
89

910
import io.minio.MinioClient;
1011
import io.minio.ServerSideEncryption;
1112
import io.minio.errors.MinioException;
1213

14+
1315
public class PutGetObjectEncryptedFile {
1416
/**
1517
* MinioClient.putObject() and MinioClient.getObject() to a file example for SSE_C.
@@ -36,7 +38,7 @@ public static void main(String[] args)
3638

3739
// To test SSE-C
3840
ServerSideEncryption sse = ServerSideEncryption.withCustomerKey(keyGen.generateKey());
39-
minioClient.putObject(bucketName, objectName, sse, inputfile);
41+
minioClient.putObject(bucketName, objectName, inputfile, null, null, sse, null);
4042
System.out.println("my-objectname is encrypted and uploaded successfully.");
4143

4244
minioClient.getObject(bucketName, objectName, sse, outputfile);

0 commit comments

Comments
 (0)