Created
December 16, 2016 12:22
-
-
Save Chetan496/22386fd54cfae6444d3a958c4f2cd035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*An example of uploading a document to the KC */ | |
public void uploadDocumentToAppianKC( | |
ContentService contentService, | |
byte[] bytes, | |
String extFileName, | |
Long folderId, | |
String uniqueIdentifier) throws InvalidContentException, StorageLimitException, PrivilegeException, | |
InsufficientNameUniquenessException, DuplicateUuidException, IOException { | |
if (bytes.length > 0) { | |
Document newDocument = new Document(); | |
newDocument.setExternalFilename(extFileName); | |
final String fileExtention = extFileName.substring(extFileName.lastIndexOf('.') + 1); | |
try { | |
String folderName = contentService.getVersion((Long) folderId, ContentConstants.VERSION_CURRENT) | |
.getDisplayName(); | |
} catch (InvalidVersionException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
if (extFileName.lastIndexOf('.') > 0) { | |
if (extFileName.lastIndexOf('\\') > 0) { | |
newDocument.setName( | |
extFileName.substring(extFileName.lastIndexOf('\\') + 1, extFileName.lastIndexOf('.'))); | |
} else { | |
newDocument.setName(extFileName.substring(0, extFileName.lastIndexOf('.'))); | |
} | |
} else if (extFileName.lastIndexOf('\\') > 0) { | |
newDocument.setName(extFileName.substring(extFileName.lastIndexOf('\\') + 1, extFileName.length() - 1)); | |
} else { | |
newDocument.setName(extFileName); | |
} | |
newDocument.setParent(folderId.longValue()); | |
if (newDocument.getExternalFilename().lastIndexOf('.') > 0) { | |
newDocument.setExtension(fileExtention); | |
} | |
newDocument.setSize(bytes.length); | |
newDocument.setDescription("Unique Identifier: " + uniqueIdentifier); | |
ContentOutputStream stream = contentService.upload(newDocument, ContentConstants.UNIQUE_NONE); | |
stream.write(bytes); | |
stream.flush(); | |
stream.close(); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment