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

Allow uploading files while preserving the actual lastModified date #174

Closed
adil192 opened this issue Dec 31, 2022 · 6 comments · Fixed by #192
Closed

Allow uploading files while preserving the actual lastModified date #174

adil192 opened this issue Dec 31, 2022 · 6 comments · Fixed by #192
Labels
bug Something isn't working package: nextcloud

Comments

@adil192
Copy link

adil192 commented Dec 31, 2022

My app Saber uses the last modified date of files to sync. Currently when a file is uploaded, its last modified date on the server is set to the upload time.

Proposition

// before
await webdav.upload(bytes, filePath);
// after (optional {DateTime? lastModified} parameter)
await webdav.upload(bytes, filePath, lastModified: someDateTime);

Alternatives I've considered

I've tried setting the lastModified props like this, but it didn't show any change in the Nextcloud web interface.

// upload file
await webdav.upload(bytes, filePath);

// set lastModified to match local file
await webdav.updateProps(filePath, {
  WebDavProps.davLastModified.name: someDateTime.toString(),
  WebDavProps.ncUploadTime.name: someDateTime.toString(),
});

nextcloud/server#15192

I can add that uploading files into nextcloud by using WebDAV also doesn't preserve the original timestamps.

not technically possible because the Webdav protocol doesn't include the local modification time

Nextcloud has a custom header X-OC-Mtime that the desktop client and the web UI sets to preserve it.
Third party clients would need to be modified to also pass this...

I'm not well-versed on Nextcloud but perhaps we need to use something other than webdav?


The Nextcloud desktop client sets the header like this:

QMap<QByteArray, QByteArray> PropagateUploadFileCommon::headers()
{
    QMap<QByteArray, QByteArray> headers;
    headers["OC-Async"] = "1";
    headers["Content-Type"] = "application/octet-stream";
    headers["X-OC-Mtime"] = QByteArray::number(qint64(_item->_modtime));
@provokateurin
Copy link
Member

I'm on vacation right now, but I'll look into it when I'm back. Updating the date via props should definitely work, maybe you need to use a different format?

@provokateurin provokateurin added bug Something isn't working package: nextcloud labels Dec 31, 2022
@adil192
Copy link
Author

adil192 commented Dec 31, 2022

I tried both someDateTime.toString() and someDateTime.toIso8601String(). I wasn't sure what format Nextcloud accepted but didn't know where to look to find out

@adil192
Copy link
Author

adil192 commented Dec 31, 2022

Just tried this DateFormat but no luck
https://github.com/provokateurin/nextcloud-neon/blob/e916fcd8f8bfe840f96f68145a2e32c994404a40/packages/nextcloud/lib/src/webdav/file.dart#L79

DateFormat('E, d MMM yyyy HH:mm:ss', 'en_US').format(lastModified);

@provokateurin
Copy link
Member

Hey sorry, I didn't have the time yet. I hope I can look at it this or next week.

@adil192
Copy link
Author

adil192 commented Jan 16, 2023

Hey sorry, I didn't have the time yet. I hope I can look at it this or next week.

There's no rush, this is a really low priority feature request from my end :)

@provokateurin
Copy link
Member

I found out that modifying the last modified time via the prop is not possible since it is readonly. The only way is to set it at upload time like I did it in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package: nextcloud
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants