public void addFile(String name, String file) throws IOException { if (boundary == null) { boundary = Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value. } files.put(name, file); }
Response doSend() throws IOException { connection.setRequestMethod(this.verb.name()); if (connectTimeout != null) { connection.setConnectTimeout(connectTimeout.intValue()); } if (readTimeout != null) { connection.setReadTimeout(readTimeout.intValue()); } if (boundary != null) { connection.setRequestProperty(CONTENT_TYPE, "multipart/form-data; boundary=" + boundary); } addHeaders(connection); if (verb.equals(Verb.PUT) || verb.equals(Verb.POST)) { addBody(connection, getByteBodyContents()); } return new Response(connection); }