Upload: Preserve file modification timestamps #1979

Open
opened 2026-02-20 01:03:41 -05:00 by deekerman · 7 comments
Owner

Originally created by @cttlee on GitHub (Dec 8, 2023).

Describe what problem this solves and why this would be valuable to many users
Describe the solution you'd like

Photoprism didn't use mtime as timestamp when no related exif info
Use mtime as timestamp as like google photo when no related exif info
The same logic can be found on immich as well
https://github.com/immich-app/immich/issues/4188

Describe alternatives you've considered

Updating by exiftool manually was difficult since files were tens of thousands, also some video formats were not supported by exiftool and some files did not have exif such as screenshot pictures.

Additional context

Originally created by @cttlee on GitHub (Dec 8, 2023). **Describe what problem this solves and why this would be valuable to many users** **Describe the solution you'd like** Photoprism didn't use mtime as timestamp when no related exif info Use mtime as timestamp as like google photo when no related exif info The same logic can be found on immich as well https://github.com/immich-app/immich/issues/4188 **Describe alternatives you've considered** Updating by exiftool manually was difficult since files were tens of thousands, also some video formats were not supported by exiftool and some files did not have exif such as screenshot pictures. **Additional context**
Author
Owner

@lastzero commented on GitHub (Dec 8, 2023):

See our User Guide FAQ at https://docs.photoprism.app/user-guide/faq/#metadata:

If there is no date information available in the metadata or the original file names, the file system modification time is used to sort pictures in search results and to create canonical file names for them during import. However, this is usually not the actual date a photo was taken (or a graphic was created by the original author), but only the time you downloaded or copied it. As a result, the date of pictures without a reliable creation date will be displayed as "Unknown" until you manually set a date in the edit dialog.

@lastzero commented on GitHub (Dec 8, 2023): See our User Guide FAQ at https://docs.photoprism.app/user-guide/faq/#metadata: > If there is no date information available in the metadata or the original file names, the file system modification time is used to sort pictures in search results and to [create canonical file names for them during import](https://docs.photoprism.app/user-guide/library/import/). However, this is usually not the actual date a photo was taken (or a graphic was created by the original author), but only the time you downloaded or copied it. As a result, the date of pictures without a reliable creation date will be displayed as "Unknown" until you manually [set a date in the edit dialog](https://docs.photoprism.app/user-guide/organize/edit/).
Author
Owner

@cttlee commented on GitHub (Dec 8, 2023):

00000.zip

I uploaded one mts and one jpeg to photoprism demo,
mtime were 2011 and 2004, but both be shown at 2023/12
螢幕擷取畫面 2023-12-08 150419
螢幕擷取畫面 2023-12-08 151035

date on google photo
螢幕擷取畫面 2023-12-08 151840

@cttlee commented on GitHub (Dec 8, 2023): [00000.zip](https://github.com/photoprism/photoprism/files/13610633/00000.zip) I uploaded one mts and one jpeg to photoprism demo, mtime were 2011 and 2004, but both be shown at 2023/12 ![螢幕擷取畫面 2023-12-08 150419](https://github.com/photoprism/photoprism/assets/449238/63c52385-6630-4221-b1a6-8f487431b1f5) ![螢幕擷取畫面 2023-12-08 151035](https://github.com/photoprism/photoprism/assets/449238/03bb5aef-63b1-4360-b08c-1a556e3b53a8) date on google photo ![螢幕擷取畫面 2023-12-08 151840](https://github.com/photoprism/photoprism/assets/449238/dde261a6-d4ae-4d6c-914b-cb1afd86d7e2)
Author
Owner

@lastzero commented on GitHub (Dec 8, 2023):

@cttlee So the feature request would be to preserve the local file system timestamps when using the web upload (which effectively creates new files on the server)?

I suppose the local time could be read through the JS File API and then transferred along with the files to preserve the time e.g. similar to this:

Screenshot 2023-12-08 at 08 19 54
Source: https://github.com/flohall/files_upload_mtime/blob/master/js/upload_mtime.js

If someone extends the frontend as needed and sends a pull request, I'd be happy to add support for preserving timestamps on the server side:

A suitable request header name for adding the information could be X-Last-Modified, ideally in some standard format e.g. as a unix timestamp or ISO date.

On the server, the code might look similar to how the "favorite" flag is preserved when uploading via WebDAV:

github.com/photoprism/photoprism@ff37fc2d53/internal/server/routes_webdav.go (L76-L82)

@lastzero commented on GitHub (Dec 8, 2023): @cttlee So the feature request would be to preserve the local file system timestamps when using the web upload (which effectively creates new files on the server)? I suppose the local time could be read through the JS File API and then transferred along with the files to preserve the time e.g. similar to this: ![Screenshot 2023-12-08 at 08 19 54](https://github.com/photoprism/photoprism/assets/301686/3ea0b4de-57e1-4da7-8998-682c75513dbd) *Source: https://github.com/flohall/files_upload_mtime/blob/master/js/upload_mtime.js* If someone extends the frontend as needed and sends a pull request, I'd be happy to add support for preserving timestamps on the server side: - https://github.com/photoprism/photoprism/blob/develop/frontend/src/dialog/upload.vue - https://developer.mozilla.org/en-US/docs/Web/API/File/lastModified A suitable request header name for adding the information could be `X-Last-Modified`, ideally in some standard format e.g. as a unix timestamp or ISO date. On the server, the code might look similar to how the "favorite" flag is preserved when uploading via WebDAV: https://github.com/photoprism/photoprism/blob/ff37fc2d536fb9110a1bec4e2a65f1884cfad3a3/internal/server/routes_webdav.go#L76-L82
Author
Owner

@phpbg commented on GitHub (Dec 9, 2023):

Hi, does your web upload uses webdav protocol? FYI nextcloud uses X-OC-MTime and X-OC-CTime headers.

See https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#request-headers

@phpbg commented on GitHub (Dec 9, 2023): Hi, does your web upload uses webdav protocol? FYI nextcloud uses `X-OC-MTime` and `X-OC-CTime` headers. See https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#request-headers
Author
Owner

@lastzero commented on GitHub (Dec 9, 2023):

We offer a WebDAV api you can use. See our documentation. The basic web upload does not use WebDAV though.

@lastzero commented on GitHub (Dec 9, 2023): We offer a WebDAV api you can use. See our documentation. The basic web upload does not use WebDAV though.
Author
Owner

@phpbg commented on GitHub (Dec 9, 2023):

OK, thanks for your info. I just saw the discussion for creation/modification timestamps over webdav happens here: https://github.com/photoprism/photoprism/discussions/2550

@phpbg commented on GitHub (Dec 9, 2023): OK, thanks for your info. I just saw the discussion for creation/modification timestamps over webdav happens here: https://github.com/photoprism/photoprism/discussions/2550
Author
Owner

@lastzero commented on GitHub (Jan 8, 2024):

@cttlee I just added an experimental implementation for setting the mtime based on the X-OC-MTime header. However, this only works with WebDAV and not with the regular file upload in the Web UI. It also requires using a WebDAV client that sends this custom header when uploading files:

Any help with testing will be much appreciated once an updated development preview is available. In the meantime, you can also test with the photoprism/photoprism:test image temporarily available on Docker Hub to test the other changes we are working on.

@lastzero commented on GitHub (Jan 8, 2024): @cttlee I just added an experimental implementation for setting the mtime based on the `X-OC-MTime` header. However, this only works with WebDAV and **not** with the regular file upload in the Web UI. It also requires using a WebDAV client that sends this custom header when uploading files: - https://github.com/photoprism/photoprism/issues/3959 Any help with testing will be much appreciated once an updated development preview is available. In the meantime, you can also test with the `photoprism/photoprism:test` image temporarily available on Docker Hub to test the other changes we are working on.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/photoprism#1979
No description provided.