String boundary = UUID.randomUUID().toString();
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
conn.connect();
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.writeBytes("--" + boundary + "--\r\n");
out.writeBytes("Content-Disposition: form-data; name=\"upload\";"
+ " filename=\"" + fileName +"\"\r\n\r\n");
IOUtils.copyAndCloseInput(in, out);
out.writeBytes("\r\n--" + boundary + "--\r\n");
out.close();
int code = conn.getResponseCode();