1

I'm currently developing a native android application and try to access some pictures on a document server. For communication I'm using the OpenCMIS library.

My goal is to download the pictures and save them to the device's internal storage or sd card. My question is, whether there is a possibility to download the files as a compressed archive like a .zip for example and extract this on the device? So instead of downloading a lot of files separately, I'd like to download one big file.

Is this something OpenCMIS is capable of? Or is this depending on the document server? I'm working with SAP Mobile Documents and know that I can download a whole folder as a .zip from the web interface over a browser, but I haven't found something about that being possible in a custom android client.

Any hints or explanations are appreciated, thanks in advance!

c7n
  • 1,131
  • 16
  • 29
  • Download as Zip isn't a CMIS service. I think your only option is to open a new zip file for writing, then stream the contents of each CMIS document into it – Gagravarr Jun 17 '15 at 22:49
  • SAP Mobile Documents provides a hidden rendition on folders (stream ID: "sap:zipRendition"). You can use getContentStream() to access it. – Florian Müller Jun 18 '15 at 12:17
  • thanks @Florian that sounds like something to work with! are there any examples available online for that since I can't seem to find any. or could you maybe provide a more detailed explanation? – c7n Jun 18 '15 at 12:54
  • 1
    Something like this should work: ContentStream zipStream = session.getContentStream(folder, "sap:zipRendition", null, null); – Florian Müller Jun 19 '15 at 15:20
  • got it working, thank you very much! a further question would be, can I only get a already existing folder as a zip or can I also get the results of a query (e.g. all files that were updated since a certain timestamp) as a zip? – c7n Jun 22 '15 at 10:26
  • That only works for folders. – Florian Müller Jun 23 '15 at 06:41

1 Answers1

1

So I got it working with help from Florian Müller.

For anyone interessted, the final code to download a folder as a .zip archive from a SAP Mobile Document Server in a native android app would look something like this:

public void downloadAsZip(Session session, Folder folder, File destination){
    ContentStream zipStream = session.getContentStream(folder, "sap:zipRendition", null, null);
    InputStream inputStream = zipStream.getStream();

    try {
        File file = new File(destination, folder.getName()+".zip");
        FileOutputStream fileOutputStream = new FileOutputStream(file);

        byte[] buffer = new byte[1024];
        int bufferLength = 0;

        while ((bufferLength = inputStream.read(buffer)) > 0) {
            fileOutputStream.write(buffer, 0, bufferLength);
        }

        fileOutputStream.close();
        inputStream.close();
    }
    catch(IOException e){
        Log.e(TAG, "An error occurred: "+e.getMessage());
    }
}
Community
  • 1
  • 1
c7n
  • 1,131
  • 16
  • 29