How to download documents from liferay from outsid

2019-03-07 02:34发布

问题:

Hi i am using liferay/api/secure/jsonws services to upload documents, getting documents, from a outside application , in the same way i want to download the documents also, i checked my liferay jsonws , there is no method or service which i can use for download , or i don't know about it , please suggest me a way to download documents from outside application , by using jsonws or any other way is also fine.

Edit after i got to know how to download document.

Hi I tried to download liferay document from outside application by using getURl, but every time for all document i am getting liferay login page content

i have already tried get-file-as-stream json-rpc call but that also giving me null response

the code which i have used is:

 final HttpHost targetHost = new HttpHost(hostname.trim());
    System.out.println(targetHost.getHostName());
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
    System.out.println(creds);
    final AuthScope authscope = new AuthScope(targetHost);
    httpclient.getCredentialsProvider().setCredentials(authscope, creds);

    final AuthCache authCache = new BasicAuthCache();
    final BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);

    final BasicHttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);

    final HttpGet httpget = new HttpGet(hostname+"/documents/" + groupId + "/" + folderId + "/" + filename);


    final HttpResponse response = httpclient.execute( httpget, localContext);

    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        final org.apache.http.HttpEntity entity = response.getEntity();

        if (entity != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            entity.writeTo(baos);
            return baos.toByteArray();
        }
    }
    return null;
} finally {
    httpclient.getConnectionManager().shutdown();
}

}

i am adding basic auth header will correct username and password, don't know how this login page is coming, is there any permission which i need to change or any configurations issue, please help in this.

回答1:

You could use the Liferay WebDav Services to download files from your document-library. The paths to download can be inspected inside of the control-panel when clicking on a file entry (WebDAV URL toogle link). The paths usually look like: /webdav/{site-name}/document_library/{folder-name}/{file-name} Otherwise, you could mimic the request URLs Liferay creates inside the documents-media portlet to download the file entry. But you should take care about authentication, when your files (and folders) are not visible to guests.



标签: liferay