Wiki
Clone wikijavarosa / MimeSubmissionAPI
Posting an instance from ODK Collect to ODK Aggregate
Post a multipart entity to http://server/submission. Confirm server url and 201 response. Sample code below.
// cycle through available xml and binary files and encode them for submission
String url = "http://server/submission";
HttpPost post = new HttpPost(url);
MultipartEntity entity = new MultipartEntity();
for (int i = 0; i < files.length; i++) {
File f = files[j];
if (f.getName().endsWith(".xml")) {
entity.addPart("xml_submission_file", new FileBody(f, "text/xml"););
} else if (f.getName().endsWith(".jpg")) {
entity.addPart(f.getName(), new FileBody(f, "image/jpeg"));
} else if (f.getName().endsWith(".3gpp")) {
entity.addPart(f.getName(), new FileBody(f, "audio/3gpp"););
} else if (f.getName().endsWith(".3gp")) {
entity.addPart(f.getName(), new FileBody(f, "video/3gpp"););
}
}
post.setEntity(entity);
// check custom header and response to ensure code is from aggregate, not proxy.
HttpResponse response = client.execute(post);
String location = response.getHeaders("Location")[0].getValue();
int code = response.getStatusLine().getStatusCode();
if (url.contains(location) && code == 201) {
System.out.println("post successful");
}
Updated