IDrive - EVS - REST API - uploadFile
try
{
String sourcePath="/test/photos/My.jpg";
String fileName="My.jpg";
String destPath="/myfiles/";
String destURL="https://<server address>/evs/uploadFile";
String output="";
fileName=="\""+fileName+"\"";
String boundary = "AaB03x";
URL u = new URL(destURL);
HttpURLConnection uc = (HttpURLConnection) u.openConnection( );
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setAllowUserInteraction(false);
uc.setRequestMethod("POST");
uc.setRequestProperty("Content-Type", "multipart/form-data; charset=UTF-8; boundary=AaB03x");
DataOutputStream dstream = new DataOutputStream(uc.getOutputStream());
dstream.writeBytes("--" + boundary + "\r\n");
dstream.writeBytes("Content-Disposition: form-data; name=\"uid\"\r\n\r\n");
dstream.writeBytes("XXXXX");
dstream.writeBytes("\r\n--" + boundary + "\r\n");
dstream.writeBytes("Content-Disposition: form-data; charset=UTF-8; name=\"pwd\"\r\n\r\n");
dstream.write(("YYYYY").getBytes("UTF-8"));
dstream.writeBytes("\r\n--" + boundary + "\r\n");
dstream.writeBytes("Content-Disposition: form-data; charset=UTF-8; name=\"pvtkey\"\r\n\r\n");
dstream.write(("ZZZZZZ").getBytes("UTF-8"));
dstream.writeBytes("\r\n--" + boundary + "\r\n");
dstream.writeBytes("Content-Disposition: form-data; charset=UTF-8; name=\"p\"\r\n\r\n");
dstream.write((destPath).getBytes("UTF-8"));
dstream.writeBytes("\r\n--" + boundary + "\r\n");
dstream.write(("Content-Disposition: form-data; charset=UTF-8; name=\"definition\"; filename="fileName+"\r\n\r\n\r\n").getBytes("UTF-8"));
File file = new File(sourcePath);
InputStream is = new FileInputStream(file);
byte[] buffer = new byte[30 * 1024];
int bytesRead = 0;
while ((bytesRead = is.read(buffer)) >= 0) {
dstream.write(buffer, 0, bytesRead);
}
dstream.writeBytes("\r\n--" + boundary + "--\r\n");
dstream.flush();
dstream.close();
InputStream iss = uc.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(iss));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null)
{
response.append(line);
}
output=response.toString();
iss.close();
}
catch (Exception e)
{
System.out.println("Exception:"+e);
}