Access files on Android Mobile

Hi all,
I need to write an Android-app in C# (XAMARIN) which opens a JSON-file available on the own-cloud.

What is the best way of opening the file? Is it better to use the REST-api on the own-cloud server (how would this work exactly?) or the Storage Access Framework (Files, how to)? The file is periodically updated, and the Android-app needs to use the latest state of the data inside.
Thanks for any suggestion.

Hi @ufotech!

I don’t see many solutions here, since it is kind of restricted from the app.

If you want to retrieve the file directly from the server, you can use a GET request. Check our DownloadRemoteFileOperation.kt class, in the owncloudComLibrary module and package. There you will be able to see the logic we use to download the file from the server, but it is pretty coupled to the rest of the logic in the app, so you will have to imitate it somehow. But it is a great guide!

Retrieving the file directly from the app is not possible due to scoped storage, which aim is precisely prevent other apps to access its files, increasing security that way :smile:.

I hope this helped you :beers:.

Thanks @Juanca !
I’ll give it a try. Any link to finding and getting started with the modules you mentioned?

br Urs

Hi @ufotech!

Sure, ownCloud is open source, you can check our code in our GitHub repository: GitHub - owncloud/android: ☎ The ownCloud Android App

1 Like

Thanks, @Juanca

After reading loads of code which you suggested, I can’t seem to manage to download the content of a file.

Reading the API-docs at
developer_manual webdav_api public_files
and this sort of call:

curl --request PROPFIND
–url remote.php dav public-files Q1M6xxxxx4erO
–header ‘Authorization: Basic cHVibxxxxxxxRVktV’
–header ‘Content-Type: application/xml; charset=UTF-8’
–header ‘Depth: 1’
–cookie ‘oc_sessionPassphrase=iHj37vOQCfxxxxbdcabc613ee’
–data ‘<?xml version="1.0"?>
<d:propfind xmlns:d=“DAV:” xmlns:oc=“…”>
<oc:public-link-item-type />
<oc:public-link-item-permission />
<oc:public-link-item-expiration />
<oc:public-link-item-share-datetime />
<oc:public-link-item-owner />

I receive as much as the properties of the file in question (w/o etag).

<d:status>HTTP/1.1 200 OK</d:status>

However, downloading does not work.

A simple Get-request to this endpoint:
remote.php dav files ?dir=/Export&fileid=1287#

Produces the following:
This is the WebDAV interface. It can only be accessed by WebDAV clients such as the ownCloud desktop sync client.

I’m now pretty much lost and ask you to guide me a bit further, if you don’t mind?


Hi @ufotech, this is a bit more complex and as I stated, it’s pretty coupled to the rest of the app. But in general terms:

  • You must do a GET call, not a PROPFIND one (that will return the details of the file but not the file itself). You can debug it with Android Studio and its Network Inspector, the request details should look something like this (you can check request and response parameters in Network Inspector):

  • You have to take into account if the server you are working with is oC10 or oCIS, because the URL will be different in each case. In the previous case, it is an oCIS server since we have the /dav/spaces/ part in the URL.

  • You need to send the authentication in a header of the request, this is, the type of authentication and the token, so that you identify as a user with access to the file (otherwise anyone could have access to the files in your server). You can check this in the “Request” section of the Network Inspector in Android Studio.

Once you do this, you will be able to retrieve the file. As I said, you can check the DownloadRemoteFileOperation.kt class, that is where we have all the logic related to this operation, but beyond this, I’m afraid I won’t be able to help you much more.

I hope this helped and that you can finally achieve what you are looking for in your own app, good luck! :smile:

1 Like

Hi @Juanca, thanks a lot for the details.

I found an answer from cdamken on the same forum, which works and is pretty simple:


It uses the public.php/webdav endpoint and the public-file-share token as a username. The password is the same as the public-file-share protection password.

It works in a curl-command as well as using insomnia and is easy to implement in C#.

Naturally, I have to share the file publicly and, for safety’s sake, protect it with password.

I also found a much more complex example w/o public sharing. There I used a neat feature of chrome. After downloading a file, in the DevTools under ‘Network’ one can right-click the download event and ‘save as curl’. It produces a functional curl-command with loads of headers and cookies and so on.

I rather take the short approach :wink:


Hi @ufotech! Nice! Glad to hear it, go for it then :rocket:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.