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
7850 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
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
0
Shivam Gupta
over 8 years ago
thanks a lot for this
and one question is when you get the document id
and you call getInternalFileUpload() but this fucntion dont have any parameter so how can you find the path of the location in KC
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Vinod Bongoni
Certified Lead Developer
over 8 years ago
To find the path use document.getInternalFilename(), where document is a object.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shivam Gupta
over 8 years ago
@vinodb thanks
suppose i created a dynamic project to upload a file . how to make it a appian plugin
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Vinod Bongoni
Certified Lead Developer
over 8 years ago
Can you plz elaborate your scenario?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shivam Gupta
over 8 years ago
@vinodb i am jst curious and trying to create the upload button so that i can upload a file in KC
I need a plugin for that
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Vinod Bongoni
Certified Lead Developer
over 8 years ago
For this, You can use Appian SAIL component "a!fileUploadField()". What is the need to create a plugin?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shivam Gupta
over 8 years ago
yes i can but i am practicing to create the same thing to learn plugin creation
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shivam Gupta
over 8 years ago
@sidhantb when i am creating a instance of document it requires three arguments parentFolderId,name, extension
how do i get parent folder id
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Sidhant Behura
over 8 years ago
@shivamg - You need to take parent folder id as input parameter.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
<
>