Downloading files using ownCloud API in java

client-development

#1

Hello Guys,

I am trying to download multiple files in java with a GET-Request using the REST API of oC, but it seems that I'm doing something wrong. I just use a simple HTTP-Protocol and normal compiled java program. I always get a unauthorized fail Exception, despite I gave my login datas by requesting for files. Do I have to configure specified things or integrate any library for that?

I would appreciate any comments and helps regarding my post.

Thanks,
Kesking03


#2

Hey @kesking03! Could you provide more details on the errors/exceptions you're getting?. How are you implementing the authentication step?

To get an idea on how a library performs this task; you can take a look at pyocclient's implementation in:


#3

Thank you for you reply, but I don't program in Python so I can't implent this code snippet.

Do I need to configure and host such a WebDav Server or can I get the files throuh de API/External Storage too?

this API gives just informations about the files in XML format: https://doc.owncloud.org/server/9.1/developer_manual/core/ocs-share-api.html

and I don't know if this one is useful:


#4

The Python library was just meant to be a reference. The implementation is fairly easy to read; you can try to follow the code to do something similar in your Java application.

No need to configure a full host for this. You can use the WebDAV API of the instance where your account lives in.

Can you provide the exact error message/logs you're seeing upon authentication. Here's a working file download request implemented with OkHTTP library in Java. To see how the basic auth. header can be formed, refer to this StackOverflow question

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://demo.owncloud.com/remote.php/dav/files/demo/Photos/Paris.jpg")
  .get()
  .addHeader("authorization", "Basic ZGVtbzpkZW1v")
  .build();

Response response = client.newCall(request).execute();