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.
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 com.owncloud.android.lib.resources.files 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 .
I receive as much as the properties of the file in question (w/o etag).
⌠oc:public-link-item-typefile</oc:public-link-item-type>
</d:prop>
<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!
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.