Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
27 replies
Subscribers
5 subscribers
Views
7857 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
Plug-Ins
How to upload fies to Knowledge center via Content Service
Shivam Gupta
over 8 years ago
I am working on a plugin creation that uploads a file to Knowledge center from your system
i know that i have to use contentService
but in contentService their is function named "upload(Document doc, java.lang.Integer unique)" which returns ContentOutputStream instance
but i am unable to understand how the document is getting saved into Knowledge center.
Anyone please help struck in this for a while
Thanks in advance
OriginalPostID-235089
Discussion posts and replies are publicly visible
Parents
0
Sidhant Behura
over 8 years ago
@shivamg
I wont be able to attach screenshots but I will surely help you with code.
Below is the code snippet of how to use create method.
private Long createDocument(String documentName, Long saveInFolder, double size, ContentService contentService) {
\ tDocument document = null;
\ tLong generatedDocument = null;
\ tint sizeInt = (int) Math.ceil(size);
\ ttry {
\ tdocument = new Document(saveInFolder, documentName, "zip");
\ tdocument.setState(ContentConstants.STATE_ACTIVE_PUBLISHED);
\ tdocument.setSize(sizeInt);
\ tdocument.setFileSystemId(ContentConstants.ALLOCATE_FSID);
\ tgeneratedDocument = contentService.create(document, ContentConstants.UNIQUE_NONE);
\ t} catch (Exception e) {
\ te.printStackTrace();
\ t}
\ treturn generatedDocument;
\t}
First create an InputStream of the original file which you want to upload.
Then use the above logic to create a document and you get the document id.
Use the document id to get the InternalFilename i.e the file path and create an OutputStream if the document created.
Then read from the InputStream and write into the OutputStream.
The document is uploaded into the KC and you have the document id too.
Now that I am aware of upload method in the Appian API i would suggest you to go for upload method because it save a lot of coding and it might be more efficient too.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Reply
0
Sidhant Behura
over 8 years ago
@shivamg
I wont be able to attach screenshots but I will surely help you with code.
Below is the code snippet of how to use create method.
private Long createDocument(String documentName, Long saveInFolder, double size, ContentService contentService) {
\ tDocument document = null;
\ tLong generatedDocument = null;
\ tint sizeInt = (int) Math.ceil(size);
\ ttry {
\ tdocument = new Document(saveInFolder, documentName, "zip");
\ tdocument.setState(ContentConstants.STATE_ACTIVE_PUBLISHED);
\ tdocument.setSize(sizeInt);
\ tdocument.setFileSystemId(ContentConstants.ALLOCATE_FSID);
\ tgeneratedDocument = contentService.create(document, ContentConstants.UNIQUE_NONE);
\ t} catch (Exception e) {
\ te.printStackTrace();
\ t}
\ treturn generatedDocument;
\t}
First create an InputStream of the original file which you want to upload.
Then use the above logic to create a document and you get the document id.
Use the document id to get the InternalFilename i.e the file path and create an OutputStream if the document created.
Then read from the InputStream and write into the OutputStream.
The document is uploaded into the KC and you have the document id too.
Now that I am aware of upload method in the Appian API i would suggest you to go for upload method because it save a lot of coding and it might be more efficient too.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
Children
No Data