content-manager-sdk / Community

Content Manager SDK Samples
http://hprm.info
The Unlicense
50 stars 37 forks source link

How do I use RecordDownload in Java? #12

Closed catmanjan closed 5 years ago

catmanjan commented 5 years ago
RecordDownload request = new RecordDownload();
request.setId(documentId);
request.setDownloadType(DownloadType.Document);
client.get(request);

client.get(request) has a return type of void, I need a byte array - here is an extract from my dto file:

 @Route(Path="/Record/{Id}/File/Resource/{Path}/{ResourceId}", Verbs="GET")
    // @Route(Path="/Record/{Id}/File/{DownloadType}", Verbs="GET")
    // @Route(Path="/Record/{Id}/File/Resource/{ResourceId}", Verbs="GET")
    @DataContract
    public static class RecordDownload implements IReturnVoid
    {
        /**
        * The Uri or Record Number of the Record.
        */
        @DataMember
        @ApiMember(DataType="string", Description="The Uri or Record Number of the Record.", IsRequired=true, Name="Id", ParameterType="path", Verb="GET")
        public String Id = null;

        /**
        * Download as an Electronic Document, HTML page or Zip file containing HTML and images.
        */
        @DataMember
        @ApiMember(DataType="DownloadType", Description="Download as an Electronic Document, HTML page or Zip file containing HTML and images.", IsRequired=true, Name="DownloadType", ParameterType="path", Verb="GET")
        public DownloadType DownloadType = null;

        /**
        * Used to load an image within an HTML rendition of an Electronic Document.
        */
        @DataMember
        @ApiMember(DataType="string", Description="Used to load an image within an HTML rendition of an Electronic Document.", Name="ResourceId", ParameterType="path", Verb="GET")
        public String ResourceId = null;

        /**
        * Some Document HTML renditions require a path as well as a resource ID to find images.
        */
        @DataMember
        @ApiMember(DataType="string", Description="Some Document HTML renditions require a path as well as a resource ID to find images.", Name="Path", ParameterType="path", Verb="GET")
        public String Path = null;

        /**
        * Indicates that the extract operation should not update the LastActionDate of a record.
        */
        @DataMember
        @ApiMember(DataType="bool", Description="Indicates that the extract operation should not update the LastActionDate of a record.", Name="SuppressLastAction", ParameterType="path", Verb="GET")
        public Boolean SuppressLastAction = null;

        public String getId() { return Id; }
        public RecordDownload setId(String value) { this.Id = value; return this; }
        public DownloadType getDownloadType() { return DownloadType; }
        public RecordDownload setDownloadType(DownloadType value) { this.DownloadType = value; return this; }
        public String getResourceId() { return ResourceId; }
        public RecordDownload setResourceId(String value) { this.ResourceId = value; return this; }
        public String getPath() { return Path; }
        public RecordDownload setPath(String value) { this.Path = value; return this; }
        public Boolean isSuppressLastAction() { return SuppressLastAction; }
        public RecordDownload setSuppressLastAction(Boolean value) { this.SuppressLastAction = value; return this; }
    }
catmanjan commented 5 years ago

This is what I've got so far - just not sure it's the "ServiceStack way"

String requestUrl =client.createUrl(request);
InputStream inputStream = client.createRequest(requestUrl, "GET", null, null).getInputStream();

ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length = 0;

while ((length = inputStream.read(buffer)) != -1) {
        byteOutputStream.write(buffer, 0, length);
}

byte[] bytes = byteOutputStream.toByteArray();
dchurchland commented 5 years ago

The download is not baked into the client. I added a new sample demonstrating one way to do a file download.

catmanjan commented 5 years ago

Thanks!