Fórum

Liferay document download in android

pratik parekh, modificado 7 Anos atrás.

Liferay document download in android

New Member Postagens: 18 Data de Entrada: 09/09/14 Postagens Recentes
I have created http Url to download document using this way

http://localhost:8080/c/document_library/get_file?uuid=b206a058-01c7-43ef-9329-e9cf39a449cc&groupId=11107

Which reqires basic authentication.

I have added this property in portal-ext.properties for basic authentication(As suggested here - how to download document using download url in liferay?) auto.login.hooks=com.liferay.portal.security.auth.BasicAuthHeaderAutoLogin

It works fine in rest client when I pass basic authentication.

But when the same Url is hit by android app (passing Url to android download manager with basic authentication in authentication header), it downloads bin file and when I click on that file it redirects me to login page of liferay.

My android code is like this:

String str = "email:password";
String enco = Base64.encodeToString(str.getBytes(), Base64.DEFAULT);
downloadManager.enqueue(new DownloadManager.Request(Uri.parse(downloadUrl))
.addRequestHeader("Authorization", "Basic " + enco)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED));


Is there any other way to download document of Liferay in mobile devices?
thumbnail
Bruno Farache, modificado 7 Anos atrás.

RE: Liferay document download in android

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
Pratikm

File download use digest authentication. Have you tried using this helper class?
pratik parekh, modificado 7 Anos atrás.

RE: Liferay document download in android

New Member Postagens: 18 Data de Entrada: 09/09/14 Postagens Recentes
Yes I have tried with that also.
It is also redirecting to login page.

I am getting following error in android.

com.liferay.mobile.android.exception.RedirectException: The requested URL has moved to http://my-ip:8080/c/portal/login?redirect=%2Fc%2Fdocument_library%2Fget_file%3Fuuid%3D1f27682f-7d35-4d2c-95e2-a1c36f2353fe%26groupId%3D11107
thumbnail
Bruno Farache, modificado 7 Anos atrás.

RE: Liferay document download in android

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
This is probably happening because you are not authenticating the request.
camilo baptista, modificado 7 Anos atrás.

RE: Liferay document download in android

New Member Mensagem: 1 Data de Entrada: 29/11/16 Postagens Recentes
I'm trying to do the file download in a android app that I'm building. I did a basic authentication, using ServerContext, but when I try to do the download, I get a message that I need a DigestAuthentication. I tried to do this using a new Session, passing a new DigestAuthentication, but the login doesn't work more.

Can you help me? How I do the DigestAuthentication?

Tks
thumbnail
Bruno Farache, modificado 7 Anos atrás.

RE: Liferay document download in android

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
Are you using the DownloadUtil class?
RAHUL Joshi, modificado 7 Anos atrás.

RE: Liferay document download in android

New Member Postagens: 6 Data de Entrada: 03/03/17 Postagens Recentes
Hi Bruno,
Can you please provide with sample code how to use DownloadUtil in android application .
thumbnail
Bruno Farache, modificado 7 Anos atrás.

RE: Liferay document download in android

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
There's a test class that shows how to use it.
RAHUL Joshi, modificado 7 Anos atrás.

RE: Liferay document download in android

New Member Postagens: 6 Data de Entrada: 03/03/17 Postagens Recentes
I tried with your implementation, but for a strange reason downloading works perfectly with the file title not containing any spaces , but throws an exception when tried with the file title with space.

Exception in thread "OkHttp Dispatcher" java.lang.AssertionError: Too many follow-up requests: 21
at org.junit.Assert.fail(Assert.java:88)
at com.ab.liferaymanager.async.FileDownloadAsyncTest$2.doFailure(FileDownloadAsyncTest.java:104)
at com.ab.liferaymanager.callback.file.DownloadCallback.doFailure(DownloadCallback.java:35)
at com.ab.liferaymanager.http.client.OkHttpClientImpl$1.onFailure(OkHttpClientImpl.java:185)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
thumbnail
Bruno Farache, modificado 7 Anos atrás.

RE: Liferay document download in android

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
Ah probably some URL encoding issue.

When you debug it, how does the URL look like and should it look like?
RAHUL Joshi, modificado 7 Anos atrás.

RE: Liferay document download in android

New Member Postagens: 6 Data de Entrada: 03/03/17 Postagens Recentes
Bruno Farache:
Ah probably some URL encoding issue.

When you debug it, how does the URL look like and should it look like?



Nope, I have already confirmed it. URL is perfectly encoded. I have even tried placing the hardcoded URL.
thumbnail
Bruno Farache, modificado 7 Anos atrás.

RE: Liferay document download in android

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
You're getting infinite redirects. Can you paste the URL you're trying to reach?
RAHUL Joshi, modificado 7 Anos atrás.

RE: Liferay document download in android

New Member Postagens: 6 Data de Entrada: 03/03/17 Postagens Recentes
I am testing on local machine but, FYI URL is http://localhost:8080/webdav/guest/document_library/being%20human.mp3