Document creation within plugin

I am trying to create a document inside a plugin code and write data into it. Could someone please help.

 

Regards,

Soujanya

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to Pradeep Gudishana

    Hi Pradeep,

    You have to upload document using a!fileUploadField. You can save Document Id in local variable to process it further.

    Please have a look at following code.

    a!fileUploadField(
          label: "File Upload",
          labelPosition: "ABOVE",
          saveInto: {
            local!docId
          },
          validations: {}
        )

     

     

  • i mean in plugin creation, i have to create a new document.
  • 0
    Certified Lead Developer
    in reply to Pradeep Gudishana
    Most plugins uploaded to community will include their source code so your best point of reference would be to download and inspect an existing plugin that performs a similar operation.
    "PDF Tools" for example shows you how to create new documents using the ContentService and how to retrieve the ID.
  • Hey,

    You can try using the upload method from ContentService

    ContentOutputStream upload(Document doc,

                              java.lang.Integer unique)

                       throws InvalidContentException,

                              StorageLimitException,

                              PrivilegeException,

                              InsufficientNameUniquenessException,

                              DuplicateUuidException

    Creates a document and provides an output stream to which the document's content should be written. The document is created using the createApproval(Content, Integer) API. The caller must write the document's data to the returned output stream and complete the upload by calling ContentOutputStream.close(). Invoking the stream's close method will calculate the size of the data written to the stream and save it as metadata for the document.

    the stream returned can be used to write like any other plain java stream.

    for more details, check the ContentService public API definition from developers tab of community.

    Hope this helps!