Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/uploader/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export class Uploader {
},
headers: {
...this._customHeaders,
'X-OC-Mtime': Math.floor(file.lastModified / 1000),
...this._mtimeHeader(file),
'OC-Total-Length': file.size,
'Content-Type': 'application/octet-stream',
},
Expand Down Expand Up @@ -579,7 +579,7 @@ export class Uploader {
url: `${tempUrl}/.file`,
headers: {
...this._customHeaders,
'X-OC-Mtime': Math.floor(file.lastModified / 1000),
...this._mtimeHeader(file),
'OC-Total-Length': file.size,
Destination: encodedDestinationFile,
},
Expand Down Expand Up @@ -633,7 +633,7 @@ export class Uploader {
},
headers: {
...this._customHeaders,
'X-OC-Mtime': Math.floor(file.lastModified / 1000),
...this._mtimeHeader(file),
'Content-Type': file.type,
},
},
Expand Down Expand Up @@ -685,4 +685,19 @@ export class Uploader {
return promise
}

/**
* Create modification time headers if valid value is available.
* It can be invalid on Android devices if SD cards with NTFS / FAT are used,
* as those files might use the NT epoch for time so the value will be negative.
*
* @param file The file to upload
*/
private _mtimeHeader(file: File): { 'X-OC-Mtime'?: number } {
const mtime = Math.floor(file.lastModified / 1000)
if (mtime > 0) {
return { 'X-OC-Mtime': mtime }
}
return {}
}

}
Loading