Download files as .zip via cmis

1.4k views Asked by At

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!

1

There are 1 answers

0
c7n On

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());
    }
}