Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using PROPFIND with custom properties (owncloud / nextcloud) #30

Closed
Bogeyx opened this issue Aug 10, 2018 · 9 comments
Closed

Using PROPFIND with custom properties (owncloud / nextcloud) #30

Bogeyx opened this issue Aug 10, 2018 · 9 comments
Assignees
Labels
Milestone

Comments

@Bogeyx
Copy link

Bogeyx commented Aug 10, 2018

Hey,
i couldn't find a documentation so: Am i doing something wrong or is there a bug?
Im trying to connect to my nextcloud webdav and get some Proeprties:

var param = new PropfindParameters();
param.Namespaces = new List<NamespaceAttr>()
{
   new NamespaceAttr("oc", "http://owncloud.org/ns"),
   new NamespaceAttr("nc", "http://nextcloud.org/ns")
};
param.CustomProperties = new List<XName>()
{
   XName.Get("fileid", "oc:"),
   XName.Get("size", "oc:"),
   XName.Get("owner-display-name", "oc:"),
   XName.Get("mount-type", "nc:"),
};
param.ApplyTo = ApplyTo.Propfind.ResourceAndAncestors;
var result = await _client.Propfind("remote.php/webdav/", param);

The Result ist valid and i get all my Resources, but without any CustomProperties.
But i know these Properties exist, because using curl i get all my CustomProperties

@skazantsev
Copy link
Owner

Hi @Bogeyx,

Could you share an example of an XML response that you're getting from the server, please?

@Bogeyx
Copy link
Author

Bogeyx commented Aug 10, 2018

Thx for the fast Answer. Doing a manual propfind with depth 1 returns:

<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
    <d:response>
        <d:href>/remote.php/webdav/</d:href>
        <d:propstat>
            <d:prop>
                <d:getlastmodified>Fri, 10 Aug 2018 11:06:30 GMT</d:getlastmodified>
                <oc:fileid>7</oc:fileid>
                <oc:size>2124220271</oc:size>
                <nc:mount-type></nc:mount-type>
                <oc:owner-display-name>Max</oc:owner-display-name>
            </d:prop>
            <d:status>HTTP/1.1 200 OK</d:status>
        </d:propstat>
    </d:response>
    <d:response>
        <d:href>/remote.php/webdav/Verwaltung/</d:href>
        <d:propstat>
            <d:prop>
                <d:getlastmodified>Wed, 08 Aug 2018 18:13:03 GMT</d:getlastmodified>
                <oc:fileid>383</oc:fileid>
                <oc:size>67701476</oc:size>
                <nc:mount-type>group</nc:mount-type>
                <oc:owner-display-name>Max</oc:owner-display-name>
            </d:prop>
            <d:status>HTTP/1.1 200 OK</d:status>
        </d:propstat>
    </d:response>
    <d:response>
        <d:href>/remote.php/webdav/Verbreitung_Fragebogen.docx</d:href>
        <d:propstat>
            <d:prop>
                <d:getlastmodified>Wed, 06 Jun 2018 20:30:01 GMT</d:getlastmodified>
                <oc:fileid>1633</oc:fileid>
                <oc:size>10993</oc:size>
                <nc:mount-type>shared</nc:mount-type>
                <oc:owner-display-name>julian</oc:owner-display-name>
            </d:prop>
            <d:status>HTTP/1.1 200 OK</d:status>
        </d:propstat>
    </d:response>
</d:multistatus>

@skazantsev
Copy link
Owner

skazantsev commented Aug 11, 2018

The response can be parsed correctly, seems like a problem in a request that is made by the lib.

Can you send me an example of a request that you're sending via curl?

Does it work if you specify only a single namespace?

var param = new PropfindParameters
{
    Namespaces = new List<NamespaceAttr> {
       new NamespaceAttr("http://owncloud.org/ns")
    }.
    CustomProperties = new List<XName> { "fileid", "size", "owner-display-name" },
    ApplyTo = ApplyTo.Propfind.ResourceAndAncestors
}

@skazantsev
Copy link
Owner

Sorry, I got confused by LINQ to XML.
I've found a way to generate a correct request.

Instead of a namespace name (oc, nc) you need to pass a namespace value to XName.Get.

Your example generates the following request:

<?xml version="1.0" encoding="utf-8"?>
<D:propfind xmlns:D="DAV:">
  <D:allprop />
  <D:include xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
    <fileid xmlns="oc" />
    <size xmlns="oc" />
    <owner-display-name xmlns="oc" />
    <mount-type xmlns="nc" />
  </D:include>
</D:propfind>

If you use the following parameters

new PropfindParameters
{
  Namespaces = new List<NamespaceAttr>
  {
    new NamespaceAttr("oc", "http://owncloud.org/ns"),
    new NamespaceAttr("nc", "http://nextcloud.org/ns")
  },
  CustomProperties = new List<XName>()
  {
    XName.Get("fileid", "http://owncloud.org/ns"),
    XName.Get("size", "http://owncloud.org/ns"),
    XName.Get("owner-display-name", "http://owncloud.org/ns"),
    XName.Get("mount-type", "http://nextcloud.org/ns"),
  },
  ApplyTo = ApplyTo.Propfind.ResourceAndAncestors
}

it generates this:

<?xml version="1.0" encoding="utf-8"?>
<D:propfind xmlns:D="DAV:">
  <D:allprop />
  <D:include xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
    <oc:fileid />
    <oc:size />
    <oc:owner-display-name />
    <nc:mount-type />
  </D:include>
</D:propfind>

I hope this request will be handled correctly by your WebDAV server.

Please let me know if it works.

@skazantsev skazantsev changed the title CustomProperties not working? Using PROPFIND with custom properties Aug 11, 2018
@Bogeyx
Copy link
Author

Bogeyx commented Aug 14, 2018

Sry for the late answer. But nope it doesnt seem to help.
dav

A working curl would be:

curl --basic --user 'user:pass' -i -X PROPFIND 'my.web.dav' -H "Depth: 1" 
-d '<?xml version="1.0"?><d:propfind  xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"><d:prop><d:getlastmodified /><oc:fileid /><oc:permissions /><oc:size /><nc:mount-type /><oc:owner-display-name /></d:prop></d:propfind>'

Content formated:

<?xml version="1.0"?>
<d:propfind  xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
   <d:prop>
      <d:getlastmodified />
      <oc:fileid />
      <oc:permissions />
      <oc:size />
      <nc:mount-type />
      <oc:owner-display-name />
   </d:prop>
</d:propfind>

Using d:include instead of d:prop doesnt work with curl, too. Don't know much about webdav, but looks like nextcloud wants it this way.

@skazantsev
Copy link
Owner

OK, so you WebDAV server doesn't support include.
Maybe creating a PROPFIND request with d:prop instead of d:allprop/d:include is better if it's supported by more WebDAV servers out there.
Seems like there's no workaround for now but I'll try to address this issue in the near future.

@skazantsev skazantsev added bug and removed question labels Aug 18, 2018
@skazantsev skazantsev changed the title Using PROPFIND with custom properties Using PROPFIND with custom properties (owncloud / nextcloud) Aug 18, 2018
@skazantsev skazantsev added this to the 2.2.3 milestone Aug 18, 2018
@skazantsev
Copy link
Owner

Hi @Bogeyx,

I have published a release 2.2.3 that adds an ability to change an issued PROPFIND request to use 'd:prop' instead of 'allprop' and 'include'.

To achieve that you need to pass PropfindRequestType.NamedProperties to PropfindParameters:

var @params = new PropfindParameters
{
	RequestType = PropfindRequestType.NamedProperties,
	CustomProperties = new XName[] {
		"{DAV:}getlastmodified",
		"{http://owncloud.org/ns}fileid",
		"{http://owncloud.org/ns}permissions",
		"{http://owncloud.org/ns}size",
		"{http://owncloud.org/ns}owner-display-name",
		"{http://nextcloud.org/ns}mount-type"
	},
	Namespaces = new[] {
		new NamespaceAttr("oc", "http://owncloud.org/ns"),
		new NamespaceAttr("nc", "http://nextcloud.org/ns")
	}
}

You can also refer to this test https://github.com/skazantsev/WebDavClient/blob/master/src/WebDav.Client.Tests/Methods/PropfindTests.cs#L269-L304

It should help integrate with WebDAV servers that don't support 'allprop' or 'include'.

@skazantsev skazantsev self-assigned this Aug 18, 2018
@Bogeyx
Copy link
Author

Bogeyx commented Aug 24, 2018

Hi,
yes it works now, thank you!

@Mubeen07
Copy link

Hi @Bogeyx,

I have published a release 2.2.3 that adds an ability to change an issued PROPFIND request to use 'd:prop' instead of 'allprop' and 'include'.

To achieve that you need to pass PropfindRequestType.NamedProperties to PropfindParameters:

var @params = new PropfindParameters
{
	RequestType = PropfindRequestType.NamedProperties,
	CustomProperties = new XName[] {
		"{DAV:}getlastmodified",
		"{http://owncloud.org/ns}fileid",
		"{http://owncloud.org/ns}permissions",
		"{http://owncloud.org/ns}size",
		"{http://owncloud.org/ns}owner-display-name",
		"{http://nextcloud.org/ns}mount-type"
	},
	Namespaces = new[] {
		new NamespaceAttr("oc", "http://owncloud.org/ns"),
		new NamespaceAttr("nc", "http://nextcloud.org/ns")
	}
}

You can also refer to this test https://github.com/skazantsev/WebDavClient/blob/master/src/WebDav.Client.Tests/Methods/PropfindTests.cs#L269-L304

It should help integrate with WebDAV servers that don't support 'allprop' or 'include'.

Hi @skazantsev
Is it possible to convert this call in postman, if yes than can you please guide me or can share an example of postman call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants