webdav-client icon indicating copy to clipboard operation
webdav-client copied to clipboard

Get etag from response when using putFileContents

Open johannesjo opened this issue 9 months ago • 4 comments

I was wondering if there is a way to get the etag from the response when using putFileContents. I know the value is there from the dev tools network panel, but was unable to find a way to do it when using this package.

johannesjo avatar Mar 21 '25 13:03 johannesjo

Also tried to make it work via customRequest but for some reason the response headers are all empty:

    const r = await client.customRequest(path, {
      headers: {
        'Content-Type': 'application/octet-stream',
        ...(isOverwrite ? {} : { 'If-None-Match': '*' }),
      },
      method: 'PUT',
      data,
    });
    console.log(r.headers);
    

johannesjo avatar Mar 21 '25 14:03 johannesjo

getDirectoryContents can return etags when using options.details: https://github.com/perry-mitchell/webdav-client?tab=readme-ov-file#item-stats

https://github.com/perry-mitchell/webdav-client?tab=readme-ov-file#getdirectorycontents

EDIT: Sorry, just saw putFileContents.. I'm not sure as I don't recall what the response contains. If it contains an etag I'd be happy supporting a detailed mode for its response.. but currently not at the moment.

perry-mitchell avatar Mar 21 '25 15:03 perry-mitchell

The response definitely contains one (at least for my nextcloud case), but for the putFileContents there is just a boolean returned. Not sure why the request headers from the customRequest are empty though.

Image

Let me know if I can help! Would be great to have this added!

johannesjo avatar Mar 22 '25 09:03 johannesjo

The headers thing could be CORS.. and if that's the case there's nothing we can do in the client. But I can see adding a detailed response option here being a good idea. I'll try to get to it at some point, if no one else does.

perry-mitchell avatar Mar 22 '25 16:03 perry-mitchell