Swagger will help in basic REST API methods, but in the case of some POST like creating data with binary I do not suggest use it.
Take a look at the implementation of the create method:
https://github.com/openkm/document-mana ... e.java#L65
You should submit a POST form with type "multipart/form-data" where the name of the file is "content" and a Document serialized with the name "doc". I will share JAVA SDK implementation for better understanding:
Code: Select all/**
* create
*/
public Document createDocument(Document doc, InputStream is) throws IOException, UnsupportedMimeTypeException,
FileSizeExceededException, UserQuotaExceededException, VirusDetectedException, ItemExistsException, PathNotFoundException,
AccessDeniedException, RepositoryException, DatabaseException, ExtensionException, AutomationException, UnknowException,
WebserviceException {
Client client = getClient();
try {
client.setChunkedEncodingSize(1024); // To prevent heap error
String uri = UriHelper.getUri(host, UriHelper.DOCUMENT_CREATE);
FormDataMultiPart multiPart = new FormDataMultiPart();
FormDataBodyPart filePart = new FormDataBodyPart("content", is, MediaType.APPLICATION_OCTET_STREAM_TYPE);
multiPart.bodyPart(filePart);
multiPart.field("doc", doc, MediaType.APPLICATION_XML_TYPE);
WebResource resource = client.resource(uri);
ClientResponse cResponse = resource.accept(MediaType.APPLICATION_XML).type(MediaType.MULTIPART_FORM_DATA_TYPE)
.post(ClientResponse.class, multiPart);
if (cResponse.getStatus() == Status.OK.getStatusCode()) {
return cResponse.getEntity(Document.class);
} else {
String error = cResponse.getEntity(String.class);
if (cResponse.getStatus() == Status.INTERNAL_SERVER_ERROR.getStatusCode()) {
if (error.indexOf(":") > 0) {
String className = error.substring(0, error.indexOf(":"));
String msg = error.substring(error.indexOf(":") + 1);
if (className.equals("IOException")) {
throw new IOException(msg);
} else if (className.equals("UnsupportedMimeTypeException")) {
throw new UnsupportedMimeTypeException(msg);
} else if (className.equals("FileSizeExceededException")) {
throw new FileSizeExceededException(msg);
} else if (className.equals("UserQuotaExceededException")) {
throw new UserQuotaExceededException(msg);
} else if (className.equals("VirusDetectedException")) {
throw new VirusDetectedException(msg);
} else if (className.equals("ItemExistsException")) {
throw new ItemExistsException(msg);
} else if (className.equals("PathNotFoundException")) {
throw new PathNotFoundException(msg);
} else if (className.equals("AccessDeniedException")) {
throw new AccessDeniedException(msg);
} else if (className.equals("RepositoryException")) {
throw new RepositoryException(msg);
} else if (className.equals("DatabaseException")) {
throw new DatabaseException(msg);
} else if (className.equals("ExtensionException")) {
throw new ExtensionException(msg);
} else if (className.equals("AutomationException")) {
throw new AutomationException(msg);
} else {
throw new UnknowException(msg);
}
} else {
throw new UnknowException("HTTP error code " + cResponse.getStatus() + ": " + error);
}
} else {
throw new UnknowException("HTTP error code " + cResponse.getStatus() + ": " + error);
}
}
} catch (ClientHandlerException e) {
throw new WebserviceException(e);
} finally {
if (client != null) {
client.destroy();
}
}
}