doc = context.getBroker().getResourceById(collectionId, resourceType, documentId);
if(doc instanceof BinaryDocument) {
final BinaryDocument bin = (BinaryDocument) doc;
final InputStream is = context.getBroker().getBinaryResource(bin);
final Base64BinaryDocument b64doc = Base64BinaryDocument.getInstance(context, is);
return b64doc;
} else {
return new NodeProxy(doc);
}
}