diff --git a/api/src/main/java/io/minio/MinioClient.java b/api/src/main/java/io/minio/MinioClient.java index 2058564a9..453db1adf 100644 --- a/api/src/main/java/io/minio/MinioClient.java +++ b/api/src/main/java/io/minio/MinioClient.java @@ -797,6 +797,11 @@ private HttpResponse execute(Method method, String region, String bucketName, St if (headerMap != null) { contentType = headerMap.get("Content-Type"); } + if (body != null && !(body instanceof InputStream || body instanceof RandomAccessFile || body instanceof byte[])) { + byte[] bytes = body.toString().getBytes(StandardCharsets.UTF_8); + body = bytes; + length = bytes.length; + } Request request = createRequest(method, bucketName, objectName, region, headerMap, queryParamMap, @@ -2490,7 +2495,7 @@ private void setBucketPolicy(String bucketName, BucketPolicy policy) String policyJson = policy.getJson(); - HttpResponse response = executePut(bucketName, null, headerMap, queryParamMap, policyJson, policyJson.length()); + HttpResponse response = executePut(bucketName, null, headerMap, queryParamMap, policyJson, 0); response.body().close(); }