Source:
public static void presignedPostPolicy_test() throws Exception { if (!mintEnv) { System.out.println("Test: presignedPostPolicy(PostPolicy policy)"); } long startTime = System.currentTimeMillis(); try { String objectName = getRandomName(); PostPolicy policy = new PostPolicy(bucketName, objectName, DateTime.now().plusDays(7)); policy.setContentRange(1 * MB, 4 * MB); Map<String, String> formData = client.presignedPostPolicy(policy); MultipartBody.Builder multipartBuilder = new MultipartBody.Builder(); multipartBuilder.setType(MultipartBody.FORM); for (Map.Entry<String, String> entry : formData.entrySet()) { multipartBuilder.addFormDataPart(entry.getKey(), entry.getValue()); } try (final InputStream is = new ContentInputStream(3 * MB)) { multipartBuilder.addFormDataPart("file", objectName, RequestBody.create(null, readAllBytes(is))); } Request.Builder requestBuilder = new Request.Builder(); String urlString = client.getObjectUrl(bucketName, ""); Request request = requestBuilder.url(urlString).post(multipartBuilder.build()).build(); OkHttpClient transport = new OkHttpClient(); Response response = transport.newBuilder() .connectTimeout(20, TimeUnit.SECONDS) .writeTimeout(20, TimeUnit.SECONDS) .readTimeout(20, TimeUnit.SECONDS) .build() .newCall(request).execute(); if (response == null) { throw new Exception("no response from server"); } if (!response.isSuccessful()) { String errorXml = ""; Scanner scanner = new Scanner(response.body().charStream()); scanner.useDelimiter("\\A"); if (scanner.hasNext()) { errorXml = scanner.next(); } scanner.close(); throw new Exception("failed to upload object. Response: " + response + ", Error: " + errorXml); } client.removeObject(bucketName, objectName); mintSuccessLog("presignedPostPolicy(PostPolicy policy)", null, startTime); } catch (Exception e) { mintFailedLog("presignedPostPolicy(PostPolicy policy)", null, startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); throw e; } }

Target:
public static void presignedPostPolicy_test() throws Exception { if (!mintEnv) { System.out.println("Test: presignedPostPolicy(PostPolicy policy)"); } long startTime = System.currentTimeMillis(); try { String objectName = getRandomName(); PostPolicy policy = new PostPolicy(bucketName, objectName, DateTime.now().plusDays(7)); policy.setContentRange(1 * MB, 4 * MB); Map<String, String> formData = client.presignedPostPolicy(policy); MultipartBody.Builder multipartBuilder = new MultipartBody.Builder(); multipartBuilder.setType(MultipartBody.FORM); for (Map.Entry<String, String> entry : formData.entrySet()) { multipartBuilder.addFormDataPart(entry.getKey(), entry.getValue()); } try (final InputStream is = new ContentInputStream(3 * MB)) { multipartBuilder.addFormDataPart("file", objectName, RequestBody.create(null, readAllBytes(is))); } Request.Builder requestBuilder = new Request.Builder(); String urlString = client.getObjectUrl(bucketName, ""); Request request = requestBuilder.url(urlString).post(multipartBuilder.build()).build(); OkHttpClient transport = new OkHttpClient().newBuilder() .connectTimeout(20, TimeUnit.SECONDS) .writeTimeout(20, TimeUnit.SECONDS) .readTimeout(20, TimeUnit.SECONDS) .build(); Response response = transport.newCall(request).execute(); if (response == null) { throw new Exception("no response from server"); } if (!response.isSuccessful()) { String errorXml = ""; Scanner scanner = new Scanner(response.body().charStream()); scanner.useDelimiter("\\A"); if (scanner.hasNext()) { errorXml = scanner.next(); } scanner.close(); throw new Exception("failed to upload object. Response: " + response + ", Error: " + errorXml); } client.removeObject(bucketName, objectName); mintSuccessLog("presignedPostPolicy(PostPolicy policy)", null, startTime); } catch (Exception e) { mintFailedLog("presignedPostPolicy(PostPolicy policy)", null, startTime, null, e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); throw e; } }