Skip to content

Commit

Permalink
make PutObjectOptions optional for putObject() file upload (#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana authored Mar 30, 2020
1 parent 9275acc commit 7e7cde9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3908,13 +3908,21 @@ public void putObject(
throw new IllegalArgumentException("empty filename is not allowed");
}

if (options == null) {
throw new IllegalArgumentException("PutObjectOptions must be provided");
}

Path filePath = Paths.get(filename);
if (!Files.isRegularFile(filePath)) {
throw new IllegalArgumentException(filename + ": not a regular file");
throw new IllegalArgumentException(filename + " not a regular file");
}

long fileSize = Files.size(filePath);
if (options == null) {
options = new PutObjectOptions(fileSize, -1);
} else if (options.objectSize() != fileSize) {
throw new IllegalArgumentException(
"file size "
+ fileSize
+ " and object size in options "
+ options.objectSize()
+ " do not match");
}

if (options.contentType().equals("application/octet-stream")) {
Expand All @@ -3924,15 +3932,6 @@ public void putObject(
}
}

if (options.objectSize() != Files.size(filePath)) {
throw new IllegalArgumentException(
"file size "
+ Files.size(filePath)
+ " and object size in options "
+ options.objectSize()
+ " does not match");
}

try (RandomAccessFile file = new RandomAccessFile(filePath.toFile(), "r")) {
putObject(bucketName, objectName, options, file);
}
Expand Down
2 changes: 1 addition & 1 deletion functional/FunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public static void putObject_test1() throws Exception {
long startTime = System.currentTimeMillis();
try {
String filename = createFile1Kb();
client.putObject(bucketName, filename, filename, new PutObjectOptions(1 * KB, -1));
client.putObject(bucketName, filename, filename, null);
Files.delete(Paths.get(filename));
client.removeObject(bucketName, filename);
mintSuccessLog(methodName, "filename: 1KB", startTime);
Expand Down

0 comments on commit 7e7cde9

Please sign in to comment.