Skip to content

Instantly share code, notes, and snippets.

@fscz
Created April 26, 2013 08:01
Show Gist options
  • Save fscz/5465635 to your computer and use it in GitHub Desktop.
Save fscz/5465635 to your computer and use it in GitHub Desktop.
TouchDB-Android Multipart AttachmentProcessing
while (atts != null && atts.nextInputStream()) {
ArrayList<String> headers = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(atts));
String line = null;
while (!"".equals((line=reader.readLine()))) {
headers.add(line);
Log.i("HEADERS", line);
}
String tmp = headers.get(0).split("filename=")[1];
String filename = tmp.substring(1, tmp.length()-1);
Map<String,Object> newAttach = (Map<String,Object>)newAttachments.get(filename);
Object revposObj = newAttach.get("revpos");
assert (revposObj != null);
int revpos = ((Integer)revposObj).intValue();
String contentType = headers.get(1).split(": ")[1];
Log.i(TDDatabase.TAG, "Insert attachment: "+filename+" with type: "+contentType);
if (contentType.contains("text")) {
GZIPInputStream gzis = new GZIPInputStream(atts);
status = insertAttachmentForSequenceWithNameAndType(gzis, newSequence, filename, contentType, revpos);
} else {
status = insertAttachmentForSequenceWithNameAndType(atts, newSequence, filename, contentType, revpos);
}
if (!status.isSuccessful()) {
return status;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment